I am trying to send a request to a REST API using an SSL certificate.
Following is the code snippet I have written:
import requests
import os
url = "https://ip_address/api"
headers = {
'Authorization': 'Bearer bearer_token'
}
path = os.path.join("/","tmp")
response = requests.request("GET", url, headers=headers, verify=os.path.join(path, "certfile.pem"))
print(response.status_code)
print(response.content)
I tried to run this on my local machine in a virtual environment and in the docker container as well. It worked fine.
Following are the configurations on my local machine:
Virtual Environment:
OS: Ubuntu 22.04.1 LTS
Python version: 3.10.6
Docker container:
Python version: 3.10.4
This same script I tried to run on one of the servers and my first colleague's Windows 11 within windows as well as in WSL. It worked fine there too.
Server 1 configurations:
OS: Ubuntu 20.04
Python version: 3.10
Following are the configurations on his machine:
Windows 11:
Python version: 3.9.6
WSL:
OS: Ubuntu 22.04.1 LTS
Python version: 3.10.6
But this same script does not work on the other colleague's machine as well as on the servers.
The following are the configurations on These machines:
Second colleague:
OS: Ubuntu 22.04
Python version: 3.8 and 3.9
Third colleague:
OS: Ubuntu 22.04
Python version: 3.9 and 3.6
Server 2 (QRadar):
OS: RHEL
python version: 3.6
Server 3:
OS: Ubuntu 22.04
Python version: 3.8
In all the above machines we are getting the following error:
requests.exceptions.SSLError: HTTPSConnectionPool(host='xx.xx.xx.xxx', port=443): Max retries exceeded with url: /api/users/self (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:877)'),))
We have tried to run the script using requests, urllib3, and httpx to figure out why.
Every time the result is the same.
It works with any of these libraries on the machine where it worked the first time.
On the machine where it gave an error, it gives an error with all of these.
What could be the issue here?
Related
This question has been answered here but for Windows users. I am getting this error on a Linux machine on a 3rd party application under a Anaconda environment. I added the following paths to my PATH env:
<path>/anaconda2/lib
<path>/anaconda2/bin
But when I run:
import requests
requests.get("https://api.ipify.org")
I get the error:
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.ipify.org',
port=443): Max retries exceeded with url: / (Caused by SSLError("Can't
connect to HTTPS URL because the SSL module is not available."))
The 3rd party application and a conda shell both include those paths in the PATH env but it only works on the shell.
The error message says "SSL module is not available". Requests uses openssl for its "SSL module" so make sure openssl is installed and working correctly.
First run:
~$ conda list
You should see openssl and pyopenssl in the output
if you don't install openssl and pyopenssl
If openssl is installed run:
~$ openssl
If you get:
openssl: error while loading shared libraries: libcrypto.so.1.0.0: cannot enable executable stack as shared object requires: Invalid argument
Run using the version number from above
~$ sudo find / -name libcrypto.so.[your version]
Then using the path to libcrypto.so.[your version] from the output of the above:
~$ sudo execstack -c [path to]/libcrypto.so.[your version]
Then run to test:
~$ openssl
OpenSSL>
You will need to do this for all environments
It turns out the _ssl.so module in the lib-dynload directory of my python environment was being overriden by the _ssl.so module in the 3rd party software, it was conflicting. So I have made a sym-link to my own module.
no matter what I do I get this error
C:\Users\MyPc>conda update --all
Solving environment: failed
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/free/win-64/repodata.json.bz2>
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.
SSLError(MaxRetryError('HTTPSConnectionPool(host=\'repo.anaconda.com\', port=443): Max retries exceeded with url: /pkgs/free/win-64/repodata.json.bz2 (Caused by SSLError("Can\'t connect to HTTPS URL because the SSL module is not available."))'))
I have searched all the internet , re-installed anaconda and did whatever is there on suggestion but this issue is still there.
Windows 10
C:\Users\MyPc>anaconda --version
anaconda Command line client (version 1.7.2)
C:\Users\MyPc>conda --version
conda 4.5.12
In my case I got this kind of error message when I try to run this command
conda install tensorflow
here is the Error message
CondaSSLError: OpenSSL appears to be unavailable on this machine. OpenSSL is required to download and install packages.
Exception: HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/main/win-64/current_repodata.json (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
This is the solution for that
step 01
go to your installation path of anaconda3
step 02
now go to the this file path
anaconda3\Library\bin
step 03
now select this DLL file and copy that
libcrypto-1_1-x64.dll
libssl-1_1-x64.dll
step 04
after that go to this file path and paste that to inside of that folder
anaconda3\DLLs
I had this same issue, and the thing that fixed it for me was to install an earlier 32-bit version of Conda. For some reason the newer 64-bit version seemed prone to this error. You can find an earlier version of Conda here:
https://repo.continuum.io/archive/
You should search for an Anaconda3 version that only has x86, not x86_64.
I had the same problem, the simple solution is:
open anaconda navigator from start menu, then run CMD.exe Prompt, and install from there, that's it.
My Django application is currently running on Python 3.4. I want to move it to 3.6, but I have an issue with SSL certificates.
The same application works perfectly fine on python 3.4. It still works fine with python3.6 within Docker container and on Windows PC. The only problem is with CentOS and RedHat (both 6.5).
My OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013.
Full error:
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>
What can I do to fix that? The problem is only for python 3.6.0 and python 3.6.1. Python 3.4 works fine with that code.
Our devops recently turned on SSL on our in-house ElasticSearch servers, while our Ubuntu dev boxes are connecting to it fine, but it's causing SSLError on Mac dev boxes (running Django).
SSLError at /search
ConnectionError(EOF occurred in violation of protocol (_ssl.c:590)) caused by: SSLError(EOF occurred in violation of protocol (_ssl.c:590))
What I know so far:
Not limited to El Capitan, also breaks on earlier version
We can connect to other ES service over https, our devops told me our ES service has higher https requirements
Openssl v0.9.8 has handshake problem on the ES service
Openssl v1.0.1 works fine on the ES service
There are many posts online around this problem but none helped.
I have tried:
brew link --force openssl (but EL Capitan is stopping it), none of the solutions worked from Homebrew refusing to link OpenSSL
adding /usr/local/opt/openssl/lib to DYLD_LIBRARY_PATH
upgrading python from 2.7.10 to 2.7.12
rebuilding virtualenv
None of the above worked...
Questions:
Is it due to OpenSSL version?
Is it due to Python version due to _ssl.c?
How do I fix this?
Finally nailed it, basically you will have to install Python that has updated openssl
check in Python cmd
import ssl
print ssl.OPENSSL_VERSION
It should print 0.9.x
Now to update:
brew install openssl, don't worry about the linking if it rejects, make sure it's >=1.x.x
'brew install python --with-brewed-openssl`
recreate virtualenv by specifying the brewed version of Python, eg. mkvirtualenv --python=/usr/.../Cellar/python/bin/python <project>
I am trying to upload a new python project from my mac to PyPI via:
python setup.py sdist upload -r pypi
When I try to upload a package, I get the following error on OSX:
Submitting dist/PyTreasuryDirect-0.1.0.tar.gz to https://pypi.python.org/pypi
error: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>
This question is slightly related to these two questions, ssl with pip and when importing the ssl library. However I need setup.py to work in my case, how can I get past this ssl error?
I also get the same error on Python 2.7.9 and Python 3.5 using OSX 10.10.2 (14C109)
The solution for OS X 10.10 is to use its default Python version 2.7.6.
This problem is related to the fact that starting from Python version 2.7.9 certificate validation for stdlib http clients is enabled by default (PEP 476). This issue is described in Python bug tracker.