Hi,
I am attempting to connect via the python Socket.IO client to a an HTTPS Socket.IO JavaScript server. When connecting via an HTTP link it works fine, but HTTPS returns "connection refused by server". The equivalent JavaScript client code however is able to connect to HTTPS, so I do not believe the issue is server side.
Here is my python-socketio client code
import socketio
sio = socketio.Client();
@sio.event
def connect():
print('connection established')
@sio.event
def disconnect():
print('disconnected from server')
sio.connect('https://myUrl.com')
sio.wait()
And here is the equivalent functioning JavaScript code
const io = require('socket.io-client');
const socket = io.connect('https://myUrl.com', {
secure: true,
reconnect: true,
rejectUnauthorized: false});
socket.on('connect', function() {
console.log("the client connected");
});
socket.on('disconnect', function() {
console.log("the client disconnected");
});
socket.on('test', function(data) {
console.log(data)
});
Is there an equivalent to the io.connect options being passed through in JavaScript that needs to be enabled on the python equivalent?
Thanks!
If the connection was refused by the server it would be useful to know why. You can enable logging to see more details, add logger=True, engineio_logger=True options when you create the client object.
Thanks for the tip!
Below is the printed received error with the URL obfuscated.
Attempting polling connection to https://myUrl.com/socket.io/?transport=polling&EIO=3
HTTP GET request to https://myUrl.com/socket.io/?transport=polling&EIO=3&t=1565367251.3249543 failed with error HTTPSConnectionPool(host='myUrl.com', port=443): Max retries exceeded with url: /socket.io/?transport=polling&EIO=3&t=1565367251.3249543 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)'))).
Does this mean that the certificate needs to be provided for the Python client unlike the JavaScript client?
Thanks
Same issue. Any help is appreciated.
Hi. I'm trying to make a connection using HTTPS in development with a self signed certificate and I think this could be related with this issue.
Using the following code:
sio = socketio.Client(engineio_logger=True, logger=True)
sio.connect("https://localhost:5000, transports="polling", namespaces=[test_namespace])
And I get the following logs:
Attempting polling connection to https://localhost:5000/socket.io/?transport=polling&EIO=3
HTTP GET request to https://localhost:5000/socket.io/?transport=polling&EIO=3&t=1571638430.3030124 failed with error HTTPSConnectionPool(host='localhost', port=5000): Max retries exceeded with url: /socket.io/?transport=polling&EIO=3&t=1571638430.3030124 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)).
So, I guess I have a problem with the cetificate. Is it possible to use a self signed certificates to create a connection or exist a workaround to do this?
It seems that the dependency python-engineio add an option ssl_verify at commit 51da0bed3c93c41b980bb565560c7233da3501f5 . Currently the last version of the library is python-engineio==3.9.3 and the change is not added yet.
It works right now if update script python-engineio/engineio/client.py for this version and connect using:
socketio.Client(engineio_logger=True, logger=True, ssl_verify=False)
Correct. Next version of python-engineio will support a disable SSL verification option. Coming out later today.
Definitely a hot button issue and much needed feature! Thank you 馃檹
python-engineio version 3.10.0 is now available with the option to disable verification of SSL certificates in the client. Enjoy!
Most helpful comment
It seems that the dependency python-engineio add an option ssl_verify at commit 51da0bed3c93c41b980bb565560c7233da3501f5 . Currently the last version of the library is python-engineio==3.9.3 and the change is not added yet.
It works right now if update script python-engineio/engineio/client.py for this version and connect using: