I have a new (May 2020) python 3.8.3 installation on windows 10 machine.
When I try to read an https url with requests.get, it fails with SSL error 'certificate verify failed'. But when I try to read the same url using urllib.request.urlopen, it works fine. Raising this as a new issue because if certificate/permission/etc. was an issue urllib.requests should have also failed.
I tried the suggestions given for Python Requests throwing SSL Error issue but without any success. Would appreciate any help.
urllib.request.urlopen works:
>>> import ssl
>>> import urllib.request
>>> ssl_context = ssl.create_default_context()
>>> r = urllib.request.urlopen('https://google.com', context = ssl_context).getcode()
>>> r
200
Requests.get Fails:
>>> import requests
>>> r = requests.get('https://google.com')
Traceback (most recent call last):
File "C:\Program Files\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Program Files\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "C:\Program Files\Python\Python38\lib\site-packages\urllib3\connectionpool.py", line 976, in _validate_conn
conn.connect()
File "C:\Program Files\Python\Python38\lib\site-packages\urllib3\connection.py", line 361, in connect
self.sock = ssl_wrap_socket(
File "C:\Program Files\Python\Python38\lib\site-packages\urllib3\util\ssl_.py", line 377, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Program Files\Python\Python38\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Program Files\Python\Python38\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Program Files\Python\Python38\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)