我对API没有太多的经验,所以对一些人来说,这个问题的答案可能是显而易见的.我正在为一个项目使用RapidAPI的Skyscanner API,每当我在RapidAPI API平台上测试端点时,它似乎工作得很好.然而,当我将代码复制到IDE(不做任何更改)时,它会抛出一系列错误,尤其是"证书验证失败"错误.以下是我使用的代码(我为这篇文章替换了键):
import requests
url = "https://skyscanner44.p.rapidapi.com/search"
querystring = {"adults":"1",
"origin":"LAX",
"destination":"DCA",
"departureDate":"2022-08-01",
"returnDate":"2022-08-15",
"cabinClass":"economy",
"currency":"USD"}
headers = {
"X-RapidAPI-Key": "XXX",
"X-RapidAPI-Host": "skyscanner44.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
以下是它引发的错误:
Traceback (most recent call last):
File "C:\Users\624237\Anaconda3\envs\atmsTesting\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\624237\Anaconda3\envs\atmsTesting\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "C:\Users\624237\Anaconda3\envs\atmsTesting\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
conn.connect()
File "C:\Users\624237\Anaconda3\envs\atmsTesting\lib\site-packages\urllib3\connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\624237\Anaconda3\envs\atmsTesting\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\624237\Anaconda3\envs\atmsTesting\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\624237\Anaconda3\envs\atmsTesting\lib\ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\624237\Anaconda3\envs\atmsTesting\lib\ssl.py", line 1070, in _create
self.do_handshake()
File "C:\Users\624237\Anaconda3\envs\atmsTesting\lib\ssl.py", line 1341, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
非常感谢您的帮助!
该工具正在尝试验证证书.尝试为请求构造函数设置更多属性,如