Cant use get chart function in blockchain python client

0 votes

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? 

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

Apr 5, 2022 in Blockchain by Soham
• 9,710 points
559 views

1 answer to this question.

0 votes

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 from it 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())

answered Apr 7, 2022 by Aditya
• 7,680 points

Related Questions In Blockchain

0 votes
1 answer

Can't open a to big .csv file in python

You can't "split a file", but you can read ...READ MORE

answered Sep 3, 2018 in Blockchain by slayer
• 29,370 points
1,021 views
0 votes
1 answer

Cant install python module for python3.6 to use Jsonrpc for altcoin

Try this  VERSION=0.1 python3 setup.py install and there's also ...READ MORE

answered Sep 7, 2018 in Blockchain by digger
• 26,740 points
910 views
0 votes
1 answer

Can't call contract function in truffle console

Inspect the object adoption within the console. You will ...READ MORE

answered Sep 28, 2018 in Blockchain by slayer
• 29,370 points
3,092 views
0 votes
1 answer

How to call function in one contract from another contract in private blockchain?

Please check whether you have byzantiumBlock: 0 in your ...READ MORE

answered Oct 1, 2018 in Blockchain by digger
• 26,740 points
859 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,922 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,426 views
0 votes
1 answer

Transaction in a blockchain

I assume you should take it as ...READ MORE

answered Apr 6, 2022 in Blockchain by Aditya
• 7,680 points
444 views
0 votes
1 answer

Can not add peer in local ethereum blockchain

You have port 30305 running in your ...READ MORE

answered Apr 7, 2022 in Blockchain by Aditya
• 7,680 points
670 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP