Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StopIteration Error for python >= 3.5 #160

Open
SufferProgrammer opened this issue Jun 5, 2017 · 2 comments
Open

StopIteration Error for python >= 3.5 #160

SufferProgrammer opened this issue Jun 5, 2017 · 2 comments

Comments

@SufferProgrammer
Copy link

SufferProgrammer commented Jun 5, 2017

hi i wonder i could get answer about my error ASAP. so i wondering around google and not found anything like this error it's only mentioning about not connect with socket.io server, connection refused, and etc. and no thing i found like mine. i wonder if this socketIO-client is not support for python version 3.5+, or there any possibility that make my code error ?

here the error trace i get
Traceback (most recent call last): File "clienio.py", line 10, in <module> socketIO = SocketIO('localhost', 5002, LoggingNamespace) File "/usr/local/lib/python3.5/dist-packages/socketIO_client-0.7.2-py3.5.egg/socketIO_client/__init__.py", line 353, in __init__ resource, hurry_interval_in_seconds, **kw) File "/usr/local/lib/python3.5/dist-packages/socketIO_client-0.7.2-py3.5.egg/socketIO_client/__init__.py", line 54, in __init__ self._transport File "/usr/local/lib/python3.5/dist-packages/socketIO_client-0.7.2-py3.5.egg/socketIO_client/__init__.py", line 62, in _transport self._engineIO_session = self._get_engineIO_session() File "/usr/local/lib/python3.5/dist-packages/socketIO_client-0.7.2-py3.5.egg/socketIO_client/__init__.py", line 76, in _get_engineIO_session transport.recv_packet())
StopIteration
DEBUG:socketIO-client:localhost:5002/socket.io [socket.io disconnect]

and here my code
import logging
from socketIO_client import SocketIO, LoggingNamespace

def on_aaa_response(*args):
print('on_aaa_response', args)

logging.getLogger("requests").setLevel(logging.WARNING)
logging.basicConfig(level=logging.DEBUG)

socketIO = SocketIO('localhost', 5002, LoggingNamespace)
socketIO.on("data", on_aaa_response)
socketIO.wait(seconds=1)

thank you for advise

@markw63
Copy link

markw63 commented Jun 5, 2017

You are trying to connect to a client at 5002. And you got a disconnect packet. (which is an Error in SocketIO-client sometimes sadly, dependent on the type of disconnect)- a ConnectionError I think. you need to trap that with try: . I use this client with Python3.5 and 3.6 so it is not a version issue. The code you are using seems confused? You are mixing structures.
socketIO is your SocketIO object from the class SocketIO.

socketIO.on("data",....) tells your socketIO class to trap the "data" event and tells it to call the function on_aaa_response.
But, the way you have coded, on_aaa_response in the class will ALSO respond to a message type "aaa_response".
ie EITHER use socketIO.on(<"messagetype">, function to call) format or the on_ format
Messages only arrive when you run SocketIO.wait(timeout), and then trigger the various functions you have setup

eg inside a class subclassed from BaseNamespace
class Watchmsg(BaseNamespace):

    def on_connect(self):
        # handles connect messages  
   def on_myownmessage(self,*args):
      # handles messages that are socket.io.emit("myownmessage",somedata)

The point is that the documentation is giving you snippets and expecting you to put your own classes/structures around it.
socketIO=SocketIO('localhost',port)
mysio=socketIO.define(Watchmsg,"/mynamespacename") # sets up a namespace around the socketIO as mysio.

now for that namespace, add an event called messagename and an function call for action
mysio.on("messagename",action)

works
as does the way I did it above - setting functions with the prefix on_ in the body of the wrapping class.

HTH
After that , see if you get errors and put some try: except: around the SocketIO.wait()

try:
    socketIO.wait(.5)

except ConnectionError as ex:
print("got connection error")

You have to import ConnectionError from SocketIO if you want it.

@MisterWil
Copy link

This is an issue with this client library connecting to a Socket IO 2.0 server. See issue #155 and pull request #158 which successfully fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants