import requests
spiders = requests.get('https://en.wikipedia.org/w/api.php')
print(spiders)
有了上面的代碼我收到以下錯誤:無法訪問維基百科API由於SSL證書錯誤
Traceback (most recent call last):
File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 554, in urlopen
self._prepare_proxy(conn)
File "C:\Python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 750, in _prepare_proxy
conn.connect()
File "C:\Python\lib\site-packages\requests\packages\urllib3\connection.py", line 252, in connect
ssl_version=resolved_ssl_version)
File "C:\Python\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 305, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Python\lib\ssl.py", line 376, in wrap_socket
_context=self)
File "C:\Python\lib\ssl.py", line 747, in __init__
self.do_handshake()
File "C:\Python\lib\ssl.py", line 983, in do_handshake
self._sslobj.do_handshake()
File "C:\Python\lib\ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)
使用證書我還得到一個錯誤:
import requests
spiders = requests.get('https://en.wikipedia.org/w/api.php',cert = 'c:\python\lib\site-packages\certifi\cacert.pem',verify = True)
print(spiders)
Traceback (most recent call last):
File "C:/Python/Files/3.py", line 3, in <module>
spiders = requests.get('https://en.wikipedia.org/w/api.php',cert = 'c:\python\lib\site-packages\certifi\cacert.pem',verify = True)
File "C:\Python\lib\site-packages\requests\api.py", line 67, in get
return request('get', url, params=params, **kwargs)
File "C:\Python\lib\site-packages\requests\api.py", line 53, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python\lib\site-packages\requests\sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python\lib\site-packages\requests\sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "C:\Python\lib\site-packages\requests\adapters.py", line 447, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL] PEM lib (_ssl.c:2824)
即使當我一直遵循一些教程時,我遇到了這個問題,當指導員有權訪問不帶問題的時候。有任何想法嗎?
指定使用證書'證書='沒有任何與驗證服務器證書。這使您可以向遠程服務器提供SSL證書以進行身份驗證。 – larsks