-1

试图运行

import blockchain
from blockchain import statistics

get_chart(chart_type="mempool-size", time_span="1year")

get_chart尽管在statistics.py文件中为客户端定义了函数,但给出了未定义的错误blockchain.info。如何运行该get_chart功能?

有没有人有任何故障排除的想法?问题已经提出了几天,我被困住了。我已经检查了 GitHub 存储库中的问题,但找不到任何问题,还没有尝试任何其他方法,因为我不确定从哪里开始。

我对任何可以从https://blockchain.info获取图表数据的 python 解决方案都很满意

4

1 回答 1

2

正如您所说,get_chart在 中定义blockchain.statistics,但导入statistics模块确实会将其成员带入全局命名空间。您必须删除它才能访问其成员,例如get_chart

from blockchain import statistics

statistics.get_chart(chart_type="mempool-size", time_span="1year")

或者,您可以直接导入该函数:

from blockchain.statistics import get_chart

get_chart(chart_type="mempool-size", time_span="1year")

不幸的是,这并不能解决手头的更大问题,即软件包的存储库似乎已被放弃。对于您的请求,它会尝试从 URL 访问数据https://blockchain.info/charts/mempool-size?format=json&timespan=1year,这会导致下载 HTML 页面而不是 JSON。

不过,您可以使用此处提供的文档访问图表 API:https ://www.blockchain.com/api/charts_api

对于您的请求,要使用的正确 URL 是:https://api.blockchain.info/charts/mempool-size?format=json&timespan=1year

您可以下载它并将 JSON 解析为字典,如下所示:

import json
from urllib.request import urlopen

url = 'https://api.blockchain.info/charts/mempool-size?format=json&timespan=1year'
data = json.loads(urlopen(url).read())
于 2021-09-30T03:49:07.760 回答