SSLError("Can't connect to HTTPS URL because the SSL module is not available.")

3,147 views
Skip to first unread message

Ryan McClellan

unread,
Oct 13, 2022, 3:21:45 PM10/13/22
to modwsgi

I have flask web app running on Apache using mod_wsgi. Web app is on a virtualhost using this config:

LoadFile "C:\Program Files (x86)\Python39-32\python39.dll"
LoadModule wsgi_module "C:/wearable/env/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win32.pyd"
WSGIPythonHome "C:/wearable/env"
WSGIApplicationGroup %{GLOBAL}
Listen 0.0.0.0:443
<VirtualHost _default_:443>
SSLEngine on
SSLCertificateFile "${SRVROOT}/conf/new_cert/ServerCertificate.crt" SSLCertificateKeyFile "${SRVROOT}/conf/new_cert/my_cert.key"
SSLCertificateChainFile "${SRVROOT}/conf/new_cert/ChainBundle1.crt"
<Directory C:/wearable/>
Require all granted
</Directory>
WSGIScriptAlias / C:/wearable/start.wsgi
</VirtualHost>

mod_wsgi/Apache is serving the web app on 443. Certificate looks good.

The problem occurs when using a function that make HTTPS call to another server. I get SSL error.
I'm able to manually run those same functions from the python virtual environment and everything works perfect. Seems like mod_wsgi isn't able to access SSL module.

Any ideas on how I can alleviate this issue? Thanks, Ryan

See following stack trace:

[Wed Oct 12 22:32:45.522680 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] Traceback (most recent call last):\r, 
[Wed Oct 12 22:32:45.522680 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] File "C:\\wearable\\__init__.py", line 92, in <module>\r, 
[Wed Oct 12 22:32:45.522680 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] cc = CariumConnector(test_mode=read_bool(conf['TEST_MODE']), logger=logger, rbe=rbe, db=db)\r, 
[Wed Oct 12 22:32:45.522680 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] File "C:\\wearable\\CariumConnector.py", line 58, in __init__\r, 
[Wed Oct 12 22:32:45.522680 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] self.kwargs = self.__login()\r,
 [Wed Oct 12 22:32:45.522680 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] File "C:\\wearable\\CariumConnector.py", line 386, in __login\r, 
[Wed Oct 12 22:32:45.522680 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] result = requests.post(f"{self.API_HOST}/identity/v1/login/", data={'username': self.__carium_user,'password': self.__carium_pass})\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] File "C:\\wearable\\env\\Lib\\site-packages\\requests\\api.py", line 115, in post\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] return request("post", url, data=data, json=json, **kwargs)\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] File "C:\\wearable\\env\\Lib\\site-packages\\requests\\api.py", line 59, in request\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] return session.request(method=method, url=url, **kwargs)\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] File "C:\\wearable\\env\\Lib\\site-packages\\requests\\sessions.py", line 587, in request\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] resp = self.send(prep, **send_kwargs)\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] File "C:\\wearable\\env\\Lib\\site-packages\\requests\\sessions.py", line 701, in send\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] r = adapter.send(request, **kwargs)\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] File "C:\\wearable\\env\\Lib\\site-packages\\requests\\adapters.py", line 563, in send\r, 
[Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] raise SSLError(e, request=request)\r,
 [Wed Oct 12 22:32:45.523679 2022] [wsgi:error] [pid 58060:tid 1952] [client 10.252.57.4:53547] requests.exceptions.SSLError: HTTPSConnectionPool(host='api.carium.com', port=443): Max retries exceeded with url: /identity/v1/login/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))\r,

Graham Dumpleton

unread,
Oct 13, 2022, 6:40:40 PM10/13/22
to mod...@googlegroups.com
Am assuming this has been resolved since you closed the issue you created.


Yes/No?

Be aware that using Anaconda Python with mod_wsgi causes all sorts of problems with SSL library usage.

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/896292b3-d60c-4bda-a970-8c1f4fe016b0n%40googlegroups.com.

Ryan McClellan

unread,
Oct 13, 2022, 7:44:32 PM10/13/22
to modwsgi
Thanks for your response,

No, issue is not resolved. I closed the issue on github after reading you direct people here for environment/setup issues.
I didn't encounter this issue when using a fresh apache install. 
I'm integrating my code base into an existing system using 32bit Apache (2.4.34). Sadly, upgrading isn't an option right now. I had to install 32bit python to get mod_wsgi to play nice with apache.
Current stack looks like: Apache/2.4.34 (Win32) OpenSSL/1.1.0h PHP/7.2.8 mod_wsgi/4.9.4 Python/3.9

Error says SSL Module not available: But using my py venv I can see ssl exists. pyopenssl is also installed:

C:\>wearable\env\Scripts\python.exe
Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:01:48) [MSC v.1929 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> print(ssl)
<module 'ssl' from 'C:\\Program Files (x86)\\Python39-32\\lib\\ssl.py'>
>>>

Let me know if you have any ideas where this could be going wrong.

Graham Dumpleton

unread,
Oct 13, 2022, 7:47:27 PM10/13/22
to mod...@googlegroups.com
The problem is likely going to be that Apache SSL module is compiled against a different SSL library version than Python and so when the Python extension verifies things it sees a mismatch and fails.

If you don't need to handler HTTPS requests in Apache, then ensure that mod_ssl is not being loaded and try again.

Ryan McClellan

unread,
Oct 13, 2022, 8:53:24 PM10/13/22
to modwsgi
Wow thanks for that information.  There is another webapp using apache to handle requests so I think mod_ssl has to stay.

Do you know a way  to recompile apache ssl module to match python's? For windows? I see lots of linux solutions for this.

Graham Dumpleton

unread,
Oct 13, 2022, 8:59:29 PM10/13/22
to mod...@googlegroups.com
No, can't help with that. Apache on Windows is already a huge pain and in general would never recommend using Apache on Windows if can avoid it.

Ryan McClellan

unread,
Oct 13, 2022, 9:16:19 PM10/13/22
to modwsgi
I understand. Thanks for your help Graham.

Ryan McClellan

unread,
Oct 21, 2022, 11:58:48 PM10/21/22
to modwsgi
I ended up solving the problem by installing a second apache service that was updated. Cheers.
Reply all
Reply to author
Forward
0 new messages