-1

Trying to run

import blockchain
from blockchain import statistics

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

Gives a function not defined error, despite get_chart being defined in the statistics.py file for the blockchain.info client. How can I run the get_chart function?

Does anyone have any troubleshooting ideas? Question has been up for a couple days and I'm stuck. I've checked the GitHub repo for issues and can't find any, haven't tried anything else yet as I'm unsure where to start.

I'm happy with any python solution that can get chart data from https://blockchain.info

Will Da Silva
  • 6,386
  • 2
  • 27
  • 52
  • Try calling it as `statistics.get_chart(chart_type="mempool-size", time_span="1year")` and it should work. Alternatively, you can do the import as `from blockchain.statistics import get_chart` and then leave the call the way it is. – Rashid 'Lee' Ibrahim Sep 29 '21 at 22:47

1 Answers1

1

As you said, get_chart is defined in blockchain.statistics, but importing the statistics module does bring its members into the global namespace. You have to dot off of it to access its members, such as get_chart:

from blockchain import statistics

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

Alternatively you can import the function directly:

from blockchain.statistics import get_chart

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

Unfortunately that won't solve the larger issue at hand which is that the repository for the package appears to be abandoned. For your request it tries to access data from the URL https://blockchain.info/charts/mempool-size?format=json&timespan=1year, which results it in downloading an HTML page instead of JSON.

Still, you can access the charts API using the docs provided here: https://www.blockchain.com/api/charts_api

For your request the correct URL to use is: https://api.blockchain.info/charts/mempool-size?format=json&timespan=1year

You can download it and parse the JSON into a dictionary like so:

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())
Will Da Silva
  • 6,386
  • 2
  • 27
  • 52
  • despite fixing my no-dotting mistake and using code as you have written above, I'm getting JSONDecodeError: Expecting value: line 1 column 1 (char 0), regardless of which chart or timespan I request. Any way to fix this? would you check to see if you have the same problem? –  Sep 30 '21 at 18:52
  • @EliBain I have updated the answer. Hopefully that will help. – Will Da Silva Sep 30 '21 at 20:53