在阅读SOF上的其他帖子时,我无法找到解决方案。每个演示和youtube都能够运行与下面列出的代码不同的场景,并获得一个没有错误的输出。
我已经为我在SOF上写的其他代码找到了很多解决方案,但是经过一整个周末的寻找,我决定写一篇关于它的文章。
提前感谢!
我的代码:
import requests
url = "https://alpha-vantage.p.rapidapi.com/query"
querystring = {"symbol":"TSLA","function":"GLOBAL_QUOTE"}
headers = {
'x-rapidapi-host': "alpha-vantage.p.rapidapi.com",
'x-rapidapi-key': "4f4624778bmsh7bd5b2d7f4e011ap154d47jsn07dedf36b055"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)错误的部分:
Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
During handling of the above exception, another exception occurred:然后再深入讨论:
MaxRetryError: HTTPSConnectionPool(host='alpha-vantage.p.rapidapi.com', port=443): Max retries
exceeded with url: /query?symbol=TSLA&function=GLOBAL_QUOTE (Caused by SSLError(SSLError("bad
handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify
failed')])")))
During handling of the above exception, another exception occurred:最后是以下内容:
SSLError: HTTPSConnectionPool(host='alpha-vantage.p.rapidapi.com', port=443): Max retries exceeded
with url: /query?symbol=TSLA&function=GLOBAL_QUOTE (Caused by SSLError(SSLError("bad handshake:
Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))发布于 2020-08-03 19:02:50
使用verify=False作为get参数
import requests
url = "https://alpha-vantage.p.rapidapi.com/query"
querystring = {"symbol":"TSLA","function":"GLOBAL_QUOTE"}
headers = {
'x-rapidapi-host': "alpha-vantage.p.rapidapi.com",
'x-rapidapi-key': "4f4624778bmsh7bd5b2d7f4e011ap154d47jsn07dedf36b055"
}
response = requests.request("GET", url, headers=headers, params=querystring, verify=False)
print(response)
print(response.text)输出:
<Response [200]>
{
"Global Quote": {
"01. symbol": "TSLA",
"02. open": "1515.0000",
"03. high": "1517.0500",
"04. low": "1420.9800",
"05. price": "1430.7600",
"06. volume": "12246960",
"07. latest trading day": "2020-07-31",
"08. previous close": "1487.4900",
"09. change": "-56.7300",
"10. change percent": "-3.8138%"
}
}https://stackoverflow.com/questions/63235381
复制相似问题