invisibleroads / socketIO-client

A socket.io client library for Python
http://pypi.python.org/pypi/socketIO-client
MIT License
447 stars 205 forks source link

Python 3.6: [WinError 10054] OR sslv3 alert bad record mac #163

Open kotvrt opened 7 years ago

kotvrt commented 7 years ago

Hello,

I'm using python 3.6 and I'm trying to connect to 2.x socket. The lib is socketIO-client-nexus 0.7.5. Here's the code:

def on_response(*args):
    print('response: ', args)

with SocketIO('https://streamer.cryptocompare.com', 443, LoggingNamespace) as socket:
    socket.on('on_response', on_response)
    socket.send("['0~Poloniex~BTC~USD']")
    socket.wait(seconds=10)

I managed to connect to this websocket on only one occassion and I got the expected response.

As soon as I quit the program and tried reconnecting later on - I encounter one of the following two scenarios:

First - WinError 10054

> Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\transports.py", line 164, in send_packet
    self._connection.send(packet)
  File "C:\Program Files\Python36\lib\site-packages\websocket\_core.py", line 234, in send
    return self.send_frame(frame)
  File "C:\Program Files\Python36\lib\site-packages\websocket\_core.py", line 259, in send_frame
    l = self._send(data)
  File "C:\Program Files\Python36\lib\site-packages\websocket\_core.py", line 423, in _send
    return send(self.sock, data)
  File "C:\Program Files\Python36\lib\site-packages\websocket\_socket.py", line 116, in send
    return sock.send(data)
  File "C:\Program Files\Python36\lib\ssl.py", line 935, in send
    return self._sslobj.write(data)
  File "C:\Program Files\Python36\lib\ssl.py", line 636, in write
    return self._sslobj.write(data)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\__init__.py", line 28, in wrap
    return f(*args, **kw)
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\__init__.py", line 225, in _message
    transport.send_packet(engineIO_packet_type, engineIO_packet_data)
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\transports.py", line 168, in send_packet
    raise ConnectionError('send disconnected (%s)' % e)
socketIO_client_nexus.exceptions.ConnectionError: send disconnected ([WinError 10054] An existing connection was forcibly closed by the remote host)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\transports.py", line 164, in send_packet
    self._connection.send(packet)
  File "C:\Program Files\Python36\lib\site-packages\websocket\_core.py", line 234, in send
    return self.send_frame(frame)
  File "C:\Program Files\Python36\lib\site-packages\websocket\_core.py", line 259, in send_frame
    l = self._send(data)
  File "C:\Program Files\Python36\lib\site-packages\websocket\_core.py", line 423, in _send
    return send(self.sock, data)
  File "C:\Program Files\Python36\lib\site-packages\websocket\_socket.py", line 116, in send
    return sock.send(data)
  File "C:\Program Files\Python36\lib\ssl.py", line 935, in send
    return self._sslobj.write(data)
  File "C:\Program Files\Python36\lib\ssl.py", line 636, in write
    return self._sslobj.write(data)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/[User]/PycharmProjects/[Project]/WebsocketConnection.py", line 26, in <module>
    socket.send("['0~Poloniex~BTC~USD']")
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\__init__.py", line 440, in send
    self.emit('message', *args, path=path)
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\__init__.py", line 433, in emit
    self._message(str(socketIO_packet_type) + socketIO_packet_data)
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\__init__.py", line 31, in wrap
    return f(*args, **kw)
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\__init__.py", line 225, in _message
    transport.send_packet(engineIO_packet_type, engineIO_packet_data)
  File "C:\Program Files\Python36\lib\site-packages\socketIO_client_nexus\transports.py", line 168, in send_packet
    raise ConnectionError('send disconnected (%s)' % e)
socketIO_client_nexus.exceptions.ConnectionError: send disconnected ([WinError 10054] An existing connection was forcibly closed by the remote host)

If I try relaunching the program however, it appears that I manage to connect, following warning pops up only before the connection is closed:

WARNING:socketIO-client:streamer.cryptocompare.com:443/socket.io [connection error] recv disconnected by SSL ([SSL: SSLV3_ALERT_BAD_RECORD_MAC] sslv3 alert bad record mac (_ssl.c:2171))

Am I doing something wrong?

rassokhin-s commented 6 years ago

Hey guys, any updates on this issue? My colleague experiences similar problem.

kotvrt commented 6 years ago

@rassokhin-s I don't think they made some progress about it otherwise I guess the issue would have been updated. I abandonded the python library and ended up creating a small program in node.js to exploit the API...

rassokhin-s commented 6 years ago

@kotvrt thanks for reply!