Skip to content Skip to sidebar Skip to footer

Python Requests Lib Is Taking Way Longer Than It Should To Do A Get Request

So I have this code. Whenever I run the code, and it gets to line 3, it takes about 20 whole seconds to do the get request. There is no reason it should be taking this long, and it

Solution 1:

It works for me most of the time.

>>>defget_balance(addr):...try:...      start = time.time()...      r = requests.get("http://blockexplorer.com/api/addr/"+addr+"/balance")...      end = time.time()...print(f"took {end - start} seconds")...print(r.text, "satoshis")...returnint(r.text)/100000000...except:...return"e"...>>>>>>get_balance("1HB5XMLmzFVj8ALj6mfBsbifRoD4miY36v")
took 0.7754228115081787 seconds
151881086 satoshis
15.1881086

But if I do this enough times in a row, I'll occasionally get the error "Bitcoin JSON-RPC: Work queue depth exceeded. Code:429"

Print out r.text like I did, and that might show you an error message from Block Explorer. It might be that they have started rate-limiting you.

Post a Comment for "Python Requests Lib Is Taking Way Longer Than It Should To Do A Get Request"