Object of type 'int' has no len() error when waiting for messages
Possibly unhandled incorrect / unexpected response from server to socketio client:
This occurred while debugging some error logic with a socketio client talking to a 3rd party server that was having connection issues.
Stacktrace
Traceback (most recent call last):
File "/home/ubuntu/code.py", line 313, in connect
await self.sio.wait()
File "/lib/python3.10/site-packages/socketio/asyncio_client.py", line 181, in wait
await self._reconnect_task
File "/lib/python3.10/site-packages/socketio/asyncio_client.py", line 477, in _handle_reconnect
await self.connect(self.connection_url,
File "/lib/python3.10/site-packages/socketio/asyncio_client.py", line 142, in connect
await self.eio.connect(real_url, headers=real_headers,
File "/lib/python3.10/site-packages/engineio/asyncio_client.py", line 114, in connect
return await getattr(self, '_connect_' + self.transports[0])(
File "/lib/python3.10/site-packages/engineio/asyncio_client.py", line 260, in _connect_polling
if await self._connect_websocket(url, headers, engineio_path):
File "/lib/python3.10/site-packages/engineio/asyncio_client.py", line 338, in _connect_websocket
pkt = packet.Packet(encoded_packet=p)
File "/lib/python3.10/site-packages/engineio/packet.py", line 27, in __init__
self.decode(encoded_packet)
File "/lib/python3.10/site-packages/engineio/packet.py", line 51, in decode
if not self.binary and len(encoded_packet) == 0:
TypeError: object of type 'int' has no len()
This might be an issue with the server sending some strange response to the client, but thought I would submit an issue just in case it is something to look at. Thanks!
Did you have logs enabled when this happened? It would help to see the logs leading to this error. Thanks.
I turned on socketio io logging and engineio logging, below is everything I could fine before / after when it occurs. The server is still flapping up and down, so let me know if you would like me to test something else.
Engine.IO connection established
Sending packet MESSAGE data 0{}
Sending packet MESSAGE data 0/priceUpdates,{}
Sending packet MESSAGE data 0/v2/user/username,{}
Attempting WebSocket upgrade to wss://site/socket.io/?token=blah&transport=websocket&EIO=4
WebSocket upgrade was successful
Unexpected error decoding packet: "object of type 'int' has no len()", aborting
Waiting for write loop task to end
Exiting write loop task
Engine.IO connection dropped
Exiting read loop task
Connection failed, new attempt in 1.11 seconds
Attempting polling connection to https://site/socket.io/?token=blah&transport=polling&EIO=4
Attempting polling connection to https://site/socket.io/?token=blah&transport=polling&EIO=4
HTTP GET request to https://site/socket.io/?token=blah&transport=polling&EIO=4&t=1666223353.366098 failed with error .
Connection failed, new attempt in 1.70 seconds
Attempting polling connection to https://site/socket.io/?token=blah&transport=polling&EIO=4
Polling connection accepted with {'sid': 'rKY3HkBYijcNa79OAAH-', 'upgrades': ['websocket'], 'pingInterval': 25000, 'pingTimeout': 20000, 'maxPayload': 1000000}
Engine.IO connection established
Sending packet MESSAGE data 0{}
Sending packet MESSAGE data 0/priceUpdates,{}
Sending packet MESSAGE data 0/v2/user/username,{}
Attempting WebSocket upgrade to wss://site/socket.io/?token=blah&transport=websocket&EIO=4
Polling connection accepted with {'sid': 'SqUXwXpAu-nblfmCAAIh', 'upgrades': ['websocket'], 'pingInterval': 25000, 'pingTimeout': 20000, 'maxPayload': 1000000}
Engine.IO connection established
Sending packet MESSAGE data 0{}
Sending packet MESSAGE data 0/priceUpdates,{}
Sending packet MESSAGE data 0/v2/user/username,{}
Attempting WebSocket upgrade to wss://site/socket.io/?token=blah&transport=websocket&EIO=4
object of type 'int' has no len()
Traceback (most recent call last):
File "code.py", line 313, in connect
await self.sio.connect(f"{WEBSOCKET_URL}?token={self._auth['auth']}", namespaces=_namespaces)
File "/Users/user/.virtualenvs/harvest-UzyqHCxN/lib/python3.10/site-packages/socketio/asyncio_client.py", line 142, in connect
await self.eio.connect(real_url, headers=real_headers,
File "/Users/user/.virtualenvs/harvest-UzyqHCxN/lib/python3.10/site-packages/engineio/asyncio_client.py", line 114, in connect
return await getattr(self, '_connect_' + self.transports[0])(
File "/Users/user/.virtualenvs/harvest-UzyqHCxN/lib/python3.10/site-packages/engineio/asyncio_client.py", line 260, in _connect_polling
if await self._connect_websocket(url, headers, engineio_path):
File "/Users/user/.virtualenvs/harvest-UzyqHCxN/lib/python3.10/site-packages/engineio/asyncio_client.py", line 338, in _connect_websocket
pkt = packet.Packet(encoded_packet=p)
File "/Users/user/.virtualenvs/harvest-UzyqHCxN/lib/python3.10/site-packages/engineio/packet.py", line 27, in __init__
self.decode(encoded_packet)
File "/Users/user/.virtualenvs/harvest-UzyqHCxN/lib/python3.10/site-packages/engineio/packet.py", line 51, in decode
if not self.binary and len(encoded_packet) == 0:
TypeError: object of type 'int' has no len()
WebSocket upgrade was successful
Unexpected error decoding packet: "object of type 'int' has no len()", aborting
Waiting for write loop task to end
Exiting write loop task
Engine.IO connection dropped
Exiting read loop task
Connection failed, new attempt in 0.65 seconds
Attempting polling connection to https://site/socket.io/?token=blah&transport=polling&EIO=4
The line:
Unexpected error decoding packet: "object of type 'int' has no len()", aborting
makes me think the server might actually be sending that string across the wire?
The log that you shared is heavily redacted. Hard to know exactly what's going on when you are sharing just one side of the conversation.
I just received a similar bug report (see right above this message for the link).
My current theory is that the server sends a WebSocket close packet at a time when the client expects a data packet. The payload of a close packet is an integer code. The client needs to check that the packet that was received is of type text or binary before consuming the data, and this would eliminate the error, and instead the client will end the connection gracefully.
This does not address the main issue, which is why the server is refusing what you are sending. Like in the other issue, you may want to look into payload size maximums that the server may have.
Unfortunately that is all the logging output I was receiving.
From what I understand, after connecting the server was accidentally trying to send a very very large message to the client, and crashing / closing connection during that process. So based on that I think your theory about the client receiving a close packet when expecting data is correct.
Oh, that's interesting. Your log is missing half of the traffic (everything that the server sends to the client), that's why I thought you were intentionally removing those logs. Anyway, I'll assume this is related to an unexpected close packet and we can reevaluate once that is addressed.