I’m having trouble implementing SSL to my aiohttp TCPSite
connection. I have a VPS set up with Ubuntu and Apache. My config files are set to enable CORS and SSL is active on the server. When I go to the actual resource ie https://irisslivedev.com:448 there are no problems, further leading me to believe that it’s a python async server problem.
On the frontend I’m getting a 404 error for the resource, which can only mean the TCPSite
server isn’t listening on the port...
right?
Here’s the code for the server:
sslcontext = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
sslcontext.load_cert_chain('cert2.pem', 'privkey2.pem')
app = web.Application()
sio = socketio.AsyncServer(cors_allowed_origins='*')
sio.attach(app)
SOCKET_PORT = 448
SERVER_URL = "irisslivedev.com"
async def runSIOWebApp(port):
# We bind our aiohttp endpoint to our app
# router
#web.run_app(self.app, host=self.server, port=self.port)
logger.log_il("Initializing Web App Runner...")
runner = web.AppRunner(app)
try:
logger.log_il("Starting Web App Runner on %s:%s..." % (SERVER_URL,port))
await runner.setup()
site = web.TCPSite(runner, SERVER_URL, port, ssl_context=sslcontext)
logger.log_il("Starting Site...")
await site.start()
while (True):
await asyncio.sleep(1)
except Exception as e:
logger.log_il("Could not start SIO Web App. %s " % e)
traceback.print_exc(file=sys.stdout)
finally:
logger.log_il("Closing Web App Runner...")
await runner.cleanup()
When I run a stacktrace this is the output:
Traceback (most recent call last):
File "il_receiver.py", line 198, in runSIOWebApp
await site.start()
File "C:\Users\jose\Python\lib\site-packages\aiohttp\web_runner.py", line 100, in start
self._server = await loop.create_server( # type: ignore
File "C:\Users\jose\Python\lib\asyncio\base_events.py", line 1459, in create_server
raise OSError(err.errno, 'error while attempting '
OSError: [Errno 10049] error while attempting to bind on address ('165.22.39.188', 443): the requested address is not valid in its context
I’m really not sure where to go from here, I’ve scoured all the resources I can find and similar answers. From what I understand, the error arises when you attempt to bind to a socket not on the local machine, or when one is already in use.
Here's my config:
``
ServerAdmin [email]
DocumentRoot /var/www/165.22.39.188/html
ServerName 165.22.39.188
Header always set Access-Control-Allow-Origin "https://irisslivedev.com"
Header always set Access-Control-Allow-Methods "*"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "*"
Header always set Access-Control-Allow-Credentials true
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerAlias irisslivedev.com
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias www.irisslivedev.com
SSLCertificateFile /cert.pem
SSLCertificateKeyFile /pkey.pem
</VirtualHost>
</IfModule>
`` If there’s any way I can make this question more clear, please let me know.