Cryptocompare API[ERROR]没有symb的数据

2024-10-04 01:31:59 发布

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

我正在使用Python,当我回忆起所有可用硬币的价格时,经常会遇到一个我无法过滤的错误“[error]没有符号XXX的数据”

代码如下:

import requests
import datetime
import cryptocompare
import datetime
coin_list = cryptocompare.get_coin_list(format=False)
date_today = datetime.datetime.now()
for coin, data in coin_list.items():
        nowprice = cryptocompare.get_historical_price(coin, 'USD', date_today)
        print (nowprice)

为什么我得到这个错误?有办法避免吗? 我如何过滤错误,使它不显示在屏幕上呢?

谢谢!!!


Tags: importgettodaydatetimedate错误符号价格
1条回答
网友
1楼 · 发布于 2024-10-04 01:31:59

这是因为您使用的API(https://www.cryptocompare.com/api/) 没有一些货币的历史信息,例如https://www.cryptocompare.com/coins/nvst/overview。除了忽略这些货币,你别无选择。在

您必须编辑cryptocompare.pyhttps://stackoverflow.com/a/12950101/5270506),并将query_cryptocompare函数更改为:

def query_cryptocompare(url,errorCheck=True):
    try:
        response = requests.get(url).json()
    except Exception as e:
        print('Error getting coin information. %s' % str(e))
        return None
    if errorCheck and 'Response' in response.keys():
        if "There is no data for the symbol" not in response['Message']:
            print('[ERROR] %s' % response['Message'])
        return None
    return response

相关问题 更多 >