2017-12-19 6 views
1

Ich bekomme eine SSLError beim Einreichen einer Anfrage gegen https://myaccount.xcelenergy.com (und bin nicht annähernd genug von einem SSL-Experten zu verstehen, warum). Kannst du mir helfen zu sehen, was das Problem ist (und wie man es angeht)?SSLError mit Anfragen und Python 3.6

Environment

  • macOS 10.13.2
  • Libressl 2.2.7
  • Python 3.6.4
  • Requests 2.18.4 (installiert (via Homebrew installiert) (via Homebrew installiert ist) über pipenv)
  • Certifi 2017.11.5 (installiert über pipenv)

-Code

import requests 

requests.get('https://myaccount.xcelenergy.com') 

Stacktrace

Traceback (most recent call last): 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/urllib3/connectionpool.py", line 595, in urlopen 
    self._prepare_proxy(conn) 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/urllib3/connectionpool.py", line 816, in _prepare_proxy 
    conn.connect() 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/urllib3/connection.py", line 326, in connect 
    ssl_context=context) 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 329, in ssl_wrap_socket 
    return context.wrap_socket(sock, server_hostname=server_hostname) 
    File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket 
    _context=self, _session=session) 
    File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in __init__ 
    self.do_handshake() 
    File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake 
    self._sslobj.do_handshake() 
    File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake 
    self._sslobj.do_handshake() 
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777) 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/requests/adapters.py", line 440, in send 
    timeout=timeout 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen 
    _stacktrace=sys.exc_info()[2]) 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment 
    raise MaxRetryError(_pool, url, error or ResponseError(cause)) 
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='myaccount.xcelenergy.com', port=443): Max retries exceeded with url:/(Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),)) 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/requests/api.py", line 72, in get 
    return request('get', url, params=params, **kwargs) 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/requests/api.py", line 58, in request 
    return session.request(method=method, url=url, **kwargs) 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/requests/sessions.py", line 508, in request 
    resp = self.send(prep, **send_kwargs) 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/requests/sessions.py", line 618, in send 
    r = adapter.send(request, **kwargs) 
    File "/Users/abach/.local/share/virtualenvs/pyxcel-PG9DCiyE/lib/python3.6/site-packages/requests/adapters.py", line 506, in send 
    raise SSLError(e, request=request) 
requests.exceptions.SSLError: HTTPSConnectionPool(host='myaccount.xcelenergy.com', port=443): Max retries exceeded with url:/(Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),)) 

Was ich (ohne Erfolg) versucht haben,

# Specifically calling out local cert chain: 
requests.get('https://myaccount.xcelenergy.com', verify='/usr/local/etc/openssl/cert.pem') 

# Using Certifi's old chain: 
requests.get('https://myaccount.xcelenergy.com', verify=certifi.old_where()) 

Antwort

1

Derzeit ist ein bekanntes Problem mit OSX's Python3.6 and OpenSSL bekannt, das möglicherweise mit dem zusammenhängt, was Sie sehen. Ich konnte es reparieren, indem ich certifi installiere und dann einen symlink im OpenSSL-Verzeichnis mache. All das kann durch Ausführen der folgenden von bash für Sie getan werden:

Applications/Python 3.6/Install Certificates.command

diese Frage im Zusammenhang Siehe: ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:747) on OS X

+0

Das tat es. Vielen Dank! – ABach