Friday, October 28, 2022

[SOLVED] Requests and Urllib3 is failing when running api get request. Can't connect to HTTPS URL because the SSL module is not available

Issue

Im using python 3.10.8 in a linux environment(RedHat 7.9 Maipo).' After installing python 3.10.8 manually with all libraries I'm facing this error:

> [root@epnm-lab ~]# python3 
> Python 3.10.8 (main, Oct 14 2022, 02:15:05)
> [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help",
> "copyright", "credits" or "license" for more information.
> >>> import requests
> >>> username = "xxx"
> >>> password = "yyy"
> >>> ip = "zzz"
> >>> requests.get(f"https://{username}:{password}@{ip}/webacs/api/v4/data/Devices?.full=true",
> verify=False)
> Traceback (most recent call last):   File
> "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 692, in urlopen
>     conn = self._get_conn(timeout=pool_timeout)   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 281, in _get_conn
>     return conn or self._new_conn()   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 1011, in _new_conn
>     raise SSLError( urllib3.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):   File
> "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line
> 489, in send
>     resp = conn.urlopen(   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 787, in urlopen
>     retries = retries.increment(   File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line
> 592, in increment
>     raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError:
> HTTPSConnectionPool(host='10.88.242.12', port=443): Max retries
> exces?.full=true (Caused by SSLError("Can't connect to HTTPS URL
> because the SSL module is not available
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):   File "<stdin>", line 1, in
> <module>   File
> "/usr/local/lib/python3.10/site-packages/requests/api.py", line 73, in
> get
>     return request("get", url, params=params, **kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in
> request
>     return session.request(method=method, url=url, **kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line
> 587, in request
>     resp = self.send(prep, **send_kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line
> 701, in send
>     r = adapter.send(request, **kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line
> 563, in send
>     raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='10.88.242.12', port=443): Max retries
> exceedefull=true (Caused by SSLError("Can't connect to HTTPS URL
> because the SSL module is not available."))
> >>> [root@epnm-lab ~]#

I've seen in others posts here, but didn't find a solution. I have installed openssl as well.

> [root@epnm-lab-02-ha-01 ~]# rpm -qa|grep ^openssl*
> openssl-1.0.2k-21.el7_9.x86_64 
> openssl-libs-1.0.2k-21.el7_9.x86_64

Is there something wrong with this? Could anyone please help me to solve this issue?


Solution

Solved!

The solution for this error is that the python version 3.10 uses openssl version 1.1.1 and my server is using openssl 1.0.2. The openssl version 1.0.2 on python 3.10 has been deprecated. So you need to install python 3.9.x 'cause this version supports openssl 1.0.2.

Hope that helps!



Answered By - Luiz Polli
Answer Checked By - Senaida (WPSolving Volunteer)