WaterSports WaterSports - 6 months ago 41
Python Question

socketIO-client can't connect to server

I'm currently trying to connect to the socketIO server like in this JavaScript:

var socket = io('https://beta.glws.org')


This is the Python part which isn't working:

from socketIO_client import SocketIO, BaseNamespace

s = SocketIO('https://beta.glws.org', 80,
verify=False,
headers={'Sec-WebSocket-Key': 'BtvJh6zvB4ILSo0sqIOntQ=='},
cookies={'io': 'SCdIBbDOGDXhUBOZAkhM',
'gat': '1',
'ga': 'GA1.2.1442748168.1463601401'
},
)


The cookies and headers are dumped from debug from the working site, but the result is the same as without them.

Result with logging on debug level:

INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): beta.glws.org
WARNING:root:beta.glws.org:80/socket.io [waiting for connection] [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (2): beta.glws.org
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (3): beta.glws.org
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (4): beta.glws.org
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (5): beta.glws.org
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (6): beta.glws.org
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (7): beta.glws.org


What am I doing wrong? Why is it starting so many new https connections?

Answer

I believe the problem is you are specifying an https address when using port 80. Port 80 is for http and port 443 is for https.

Here is part of the line of code you should change.

'https://beta.glws.org', 80,

You can either use the http protocol for the address and port 80 or you can change the port to 443 and leave the address the same.