Testing out a simple piece of code with Anaconda3:
import requests as req
resp = req.get("https://api.github.com")
print(resp.text)
And I get this error:
SSLError: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
Using the debugger to follow the calls, the problem seems to be occurring in get_netrc_auth()
in requests.utils. Here, this code is used to get the full path to the netrc file:
for f in NETRC_FILES:
try:
loc = os.path.expanduser('~/{}'.format(f))
However, this just gives the path to my home directory, whereas netrc is in the Lib
directory of the working environment.
Apparently, I have an environment variable set incorrectly somewhere. Suggestions?
EDIT TO QUESTION:
Per Steffen's response, netrc does not appear to be the problem. Marsiliou's suggestion on directly including the path to the cert file (i.e.
resp = req.get("https://api.github.com" verify='/path/to/certfile')
) did work... once... yesterday.
My code now looks like this:
import requests as req
from os import environ
cert_path = environ['CONDA_PREFIX'] + '\Lib\site-packages\certifi\cacert.pem'
print (cert_path)
resp = req.get("https://api.github.com", verify= cert_path)
print(resp.text)
cert_path
expands to C:\ProgramData\Anaconda3\Lib\site-packages\certifi\cacert.pem
This results in the same SSLError. Any suggestions (other than setting verify
to False
)?
PS - And to answer Steffen's other questions - This is Anaconda3, Python 3.7.3, on Windows 10.