Hi,
I'm trying to build an app with aiohttp and your socketio library, your examples are quite clear and helpful!
However, I'm wondering if the library really support https? Your example (https://github.com/miguelgrinberg/python-socketio/blob/master/examples/server/aiohttp/app.py) works well with http, but when i change it to use https, it seems to be flipping between connected and disconnected quickly and cannot work properly. Would you mind have a look?
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.load_cert_chain('ssl.crt', 'ssl.key')
web.run_app(app, ssl_context=ssl_context)
Thank you so much~~~

Did you enable logs in the server to see why it is failing these requests? Add engineio_logger=True and logger=True to your AsyncServer() constructor to enable detailed logs.
This library does not really care about SSL, that is a property of the web server.
I have enabled the log for aiohttp server, and this is the log:
Server initialized for aiohttp.
======== Running on https://0.0.0.0:8443 ========
(Press CTRL+C to quit)
emitting event "my_response" to all [/]
emitting event "my_response" to all [/]
f11847af7c8a4d0fbb02f5afea531ec9: Sending packet OPEN data {'sid': 'f11847af7c8a4d0fbb02f5afea531ec9', 'upgrades': [
Timeout': 60000, 'pingInterval': 25000}
emitting event "my_response" to f11847af7c8a4d0fbb02f5afea531ec9 [/]
f11847af7c8a4d0fbb02f5afea531ec9: Sending packet MESSAGE data 2["my_response",{"data":"Connected","count":0}]
f11847af7c8a4d0fbb02f5afea531ec9: Sending packet MESSAGE data 0
https://127.0.0.1:8443 is not an accepted origin.
https://127.0.0.1:8443 is not an accepted origin.
https://127.0.0.1:8443 is not an accepted origin.
ead4129bf04545129c029c4d28cd9450: Sending packet OPEN data {'sid': 'ead4129bf04545129c029c4d28cd9450', 'upgrades': [
Timeout': 60000, 'pingInterval': 25000}
emitting event "my_response" to ead4129bf04545129c029c4d28cd9450 [/]
ead4129bf04545129c029c4d28cd9450: Sending packet MESSAGE data 2["my_response",{"data":"Connected","count":0}]
ead4129bf04545129c029c4d28cd9450: Sending packet MESSAGE data 0
https://127.0.0.1:8443 is not an accepted origin.
https://127.0.0.1:8443 is not an accepted origin.
https://127.0.0.1:8443 is not an accepted origin.
emitting event "my_response" to all [/]
f11847af7c8a4d0fbb02f5afea531ec9: Sending packet MESSAGE data 2["my_response",{"data":"Server generated event number
ead4129bf04545129c029c4d28cd9450: Sending packet MESSAGE data 2["my_response",{"data":"Server generated event number
7c2b0ff93c34424b9d88bc4d6cb0038b: Sending packet OPEN data {'sid': '7c2b0ff93c34424b9d88bc4d6cb0038b', 'upgrades': [
Timeout': 60000, 'pingInterval': 25000}
emitting event "my_response" to 7c2b0ff93c34424b9d88bc4d6cb0038b [/]
7c2b0ff93c34424b9d88bc4d6cb0038b: Sending packet MESSAGE data 2["my_response",{"data":"Connected","count":0}]
7c2b0ff93c34424b9d88bc4d6cb0038b: Sending packet MESSAGE data 0
https://127.0.0.1:8443 is not an accepted origin.
https://127.0.0.1:8443 is not an accepted origin.
https://127.0.0.1:8443 is not an accepted origin.
I thought it is related to my SSL key files, though running the server application on a machine I was sure about its keys also gave me the same result (with the name of the server in the log, instead of 127.0.0.1.
A part of client console log:
pip freeze:
aiohttp==3.6.2
async-timeout==3.0.1
attrs==19.3.0
chardet==3.0.4
idna==2.9
idna-ssl==1.1.0
multidict==4.7.5
netifaces==0.10.6
pkg-resources==0.0.0
python-engineio==3.11.2
python-socketio==4.4.0
six==1.14.0
socketio==0.2.1
typing-extensions==3.7.4.1
yarl==1.4.2
@miguelgrinberg Thanks for replying~ I'm able to see the log and debug now.
@ralthor I got the same log as you and I think enabling cors_allowed_origins solves the problem.
sio = socketio.AsyncServer(async_mode='aiohttp', logger=True, engineio_logger=True, cors_allowed_origins='*')
@LilyHolms Thank you for the solution. It fixed the server issue.
I am also using the thread client, which did not connect until I disabled the ssl verification (although I am sure about the certificate files on the server):
sio = socketio.Client(engineio_logger=True, ssl_verify=False)
Most helpful comment
@miguelgrinberg Thanks for replying~ I'm able to see the log and debug now.
@ralthor I got the same log as you and I think enabling cors_allowed_origins solves the problem.