【Python】【BugList13】req = requests.get(url=target)报错: (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)')

【代码】

# -*- coding:UTF-8 -*-
import requests
if __name__ == '__main__':
target = 'https://unsplash.com/'
req = requests.get(url=target)
print(req.text)

【报错】

=================== RESTART: F:/PySouce/spiderphotos_1.py ===================
Traceback (most recent call last):
File "D:\Program Files\python36\lib\site-packages\urllib3\connectionpool.py", line 594, in urlopen
self._prepare_proxy(conn)
File "D:\Program Files\python36\lib\site-packages\urllib3\connectionpool.py", line 815, in _prepare_proxy
conn.connect()
File "D:\Program Files\python36\lib\site-packages\urllib3\connection.py", line 356, in connect
ssl_context=context)
File "D:\Program Files\python36\lib\site-packages\urllib3\util\ssl_.py", line 359, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "D:\Program Files\python36\lib\ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "D:\Program Files\python36\lib\ssl.py", line 814, in __init__
self.do_handshake()
File "D:\Program Files\python36\lib\ssl.py", line 1068, in do_handshake
self._sslobj.do_handshake()
File "D:\Program Files\python36\lib\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 "D:\Program Files\python36\lib\site-packages\requests\adapters.py", line 445, in send
timeout=timeout
File "D:\Program Files\python36\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "D:\Program Files\python36\lib\site-packages\urllib3\util\retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='unsplash.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 "F:/PySouce/spiderphotos_1.py", line 5, in <module>
req = requests.get(url=target)
File "D:\Program Files\python36\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "D:\Program Files\python36\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "D:\Program Files\python36\lib\site-packages\requests\sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "D:\Program Files\python36\lib\site-packages\requests\sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "D:\Program Files\python36\lib\site-packages\requests\adapters.py", line 511, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='unsplash.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))
>>>

【解决方法】

# -*- coding:UTF-8 -*-
import requests
if __name__ == '__main__':
target = 'https://unsplash.com/'
req = requests.get(url=target,verify=False)
print(req.text)
上一篇:Servlet 使用ServletConfig对象来配置Servlet


下一篇:点击返回上一页 wx.navigateTo不管用了