Error with SSL certificate when using Python shell

2

I get errors when I use Python's requests.get to get info from any site:

Traceback (most recent call last):   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 603, in urlopen
    chunked=chunked)   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 344, in _make_request
    self._validate_conn(conn)   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 843, in _validate_conn
    conn.connect()   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 370, in connect
    ssl_context=context)   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 355, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 423, in wrap_socket
    session=session   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 870, in _create
    self.do_handshake()   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1139, in do_handshake
    self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='e.mail.ru', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "C:\Users\ADMIN\Desktop\test1.py", line 3, in <module>
    r=requests.get("https://e.mail.ru")   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)   File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='e.mail.ru', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))

Also when I use pip install, there is the same error:

C:\WINDOWS\system32>cd C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\scripts

C:\Users\ADMIN\AppData\Local\Programs\Python\Python37\Scripts>pip install ssl
Collecting ssl
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /simple/ssl/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /simple/ssl/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /simple/ssl/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /simple/ssl/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /simple/ssl/
  Could not fetch URL https://pypi.org/simple/ssl/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/ssl/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))) - skipping
  Could not find a version that satisfies the requirement ssl (from versions: )
No matching distribution found for ssl
You are using pip version 19.0.3, however version 19.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

I tried to make site URL trusted with

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools

but I've got nothing.

I use Windows 8, Python 3.7.4, and pip 19.0.3.

I know that I can ignore SSL verification using

r = requests.get(url = URL, verify=False)

but I still cannot use pip install now and would rather not need to consistently ignore these errors.

Yulya Polezhaeva

Posted 2019-07-24T20:07:32.923

Reputation: 21

Please copy and paste your error messages again, putting them between triple-backticks (\```) the way I did at the bottom of the question. – G-Man Says 'Reinstate Monica' – 2019-07-25T18:10:14.380

Just a comment, but you may want to try downgrading to Python 3.7.3 temporarily, or at least reinstalling 3.7.4. As a side note, while I am assuming it is merely an example, pip install ssl would fail anyway (that module is apparently strictly for Python 2.x).

– Anaksunaman – 2019-07-30T08:21:11.507

Answers

0

Make these changes to your code, and it should work :

from urllib3.exceptions import InsecureRequestWarning
.
.
.
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
r = requests.get(url=URL, verify=False)

dmdip

Posted 2019-07-24T20:07:32.923

Reputation: 101