使用Python请求修复SSL认证错误
系统设置: macOS 10.14.1 Python 3.7.0 pip 18.1 我以前写的代码很有效,但现在运行时,出现以下错误:使用Python请求修复SSL认证错误,python,macos,ssl,python-requests,ssl-certificate,Python,Macos,Ssl,Python Requests,Ssl Certificate,系统设置: macOS 10.14.1 Python 3.7.0 pip 18.1 我以前写的代码很有效,但现在运行时,出现以下错误: urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)> 此代码来自一个包;我没有写这段代码
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)>
此代码来自一个包;我没有写这段代码
编辑:
下面是完整的错误消息
/Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1016, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 956, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1392, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 850, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)
如果这是一个SSL问题,我怀疑我该如何重置为系统默认值?除了通过Python请求请求之外,我从未涉足过SSL或连接,因此我不知道如何更改某些内容。问题在于macOS上的Python 3.7。Python 3.7中包含一个README.rtf,其中说明了以下内容: Python 3.7的这个变体包括它自己的OpenSSL 1.1.0的私有副本。不再使用不推荐使用的Apple提供的OpenSSL库。这意味着由Keychain访问应用程序和security命令行实用程序管理的系统和用户密钥链中的信任证书不再被Python ssl模块用作默认值
同一文件夹中包含一个命令,该命令通过certifi安装Python 3.7使用的证书包。看起来服务器提供了错误的SSL证书。因此,这是一个服务器问题。可能是由于多种原因,您的证书包中可能缺少根CA等。您需要添加有问题的代码,并且更具体。该问题没有提供足够的详细信息来重现该问题,即问题太广泛。如果它以前工作,现在不工作,并且您对系统所做的更改为零,那么问题很可能出现在您的系统之外,即服务器设置中断或类似ssl拦截防火墙的中间包。相反,如果您对系统进行了更改,您还需要查看您所做的更改,例如更新Python、安装或删除模块、安装或升级或重新配置可能执行SSL拦截的防病毒。设置verify=False以禁用它。如果有效,该问题应为重复问题,可能会有帮助:
/Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1016, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 956, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1392, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 850, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)