Python Forum

Full Version: Add Tor proxy to blockchain API call
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
He everyone.
I am trying to call blockchain address detail endpoint several times. After a while my IP is blocked, and the response of my call is 429 Too Many request.
I would like to add Tor proxy redirection to my method, in order to get a new IP address once at 5-10 calls. Tor proxy is generating a new IP every 5 seconds. Usually I am getting banned after 20 seconds if I call the resource in 5 threads (each thread same IP).
Could you please provide a implementation at my python method with call redirection through TOR?
I need this in order to make unlimited calls to blockchain address detail endpoint. Endpoint call Example: Get on https://blockchain.info/multiaddr?active={addr}&n=1. Where {addr} is substituted with a btc public address, Example: https://blockchain.info/multiaddractive=...fgX2pa&n=1
Note:
the endpoint will be called from multiple threads or multiprocessing. Every thread should have it unique IP. I need a logic that will get each thread a valid Unique IP then make the call.
Below is my python method:

def getBalance(addr):
    try:
        time.sleep(1)
        response = requests.get(
            f'https://blockchain.info/multiaddr?active={addr}&n=1')

        return (
            response.json()['wallet']
        )
    except:
        print("your Ip got banned. Turn your VPN on")
        time.sleep(5)
        getBalance(addr)
        pass
getBalance() Method is called by each thread.