正如您所说,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×pan=1year
,这会导致下载 HTML 页面而不是 JSON。
不过,您可以使用此处提供的文档访问图表 API:https ://www.blockchain.com/api/charts_api
对于您的请求,要使用的正确 URL 是:https://api.blockchain.info/charts/mempool-size?format=json×pan=1year
您可以下载它并将 JSON 解析为字典,如下所示:
import json
from urllib.request import urlopen
url = 'https://api.blockchain.info/charts/mempool-size?format=json×pan=1year'
data = json.loads(urlopen(url).read())