gpt4 book ai didi

python - 我缺少什么来修复与金融 API 相关的 SSL 错误?

转载 作者:行者123 更新时间:2023-12-04 22:43:08 26 4
gpt4 key购买 nike

阅读 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')])")))

最佳答案

使用verify=False作为获取参数

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%"
}
}

关于python - 我缺少什么来修复与金融 API 相关的 SSL 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63235381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com