我一直在使用 Romel Torres 的 alpha_vantage 包,但也想直接从 python 使用 Alpha Vantage API(提供更强大的功能)和包请求,如下所述CALL with CURL an API through Python:
import requests
import alpha_vantage
API_URL = "https://www.alphavantage.co/query"
data = {
"function": "TIME_SERIES_DAILY",
"symbol": "NIFTY",
"outputsize": "compact",
"datatype": "csv"
"apikey": "XXX",
}
response = requests.get(API_URL, data)
print(response.json())[/code]
但是在返回的字典中收到以下错误消息:
{'错误消息':'无效的 API 调用。请重试或访问 TIME_SERIES_DAILY 的文档 ( https://www.alphavantage.co/documentation/ )。'}
使用 requests.post() 的结果是:
response = requests.post(API_URL, data)
{'detail': 'Method "POST" not allowed.'}
我重新检查了文档并遵循了所有必需的 API 参数。感谢我在这里可能缺少的一些帮助以及正确的调用和/或任何其他替代方法。谢谢