Alpha Vantage API CryptoCurrences ValueError:从API获取数据时出错,未给出任何返回

2024-10-06 21:24:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用Alpha Vantage API接收不同加密货币的健康指数。为了提取健康指数,我使用了两种不成功的方法: 方法:使用python Alpha Vantage库进行调用

from alpha_vantage.cryptocurrencies  import CryptoCurrencies
ts = CryptoCurrencies(key="my_key", output_format="pandas")
data= ts.get_digital_crypto_rating(symbol='BTC')
print(data)

运行它时,我收到以下错误

ValueError: Error getting data from the api, no return was given.

B'way:使用直接调用API

import requests
API_URL = "https://www.alphavantage.co/query" 
parameters = {
         "function": "CRYPTO_RATING",
         "symbol": "BTC", 
         "apikey": "my_key"}
response = requests.get(API_URL,  params=parameters)
print(response.json())

使用这种方法,它似乎成功地进行了API调用,因为我接收<Response [200]>,但接收数据的打印是{}


Tags: 方法keyfromimportalphaapidataget