2

I'm currently using this method to connect to web3py

infura_url = "https://node.node/asdasdasdasdasd/bsc/mainnet/archive/" # fast
web3 = Web3(Web3.HTTPProvider(infura_url))

How do I enable proxy? say i have proxy at '321.123.121.123:8081'

Progman
  • 16,827
  • 6
  • 33
  • 48
user40780
  • 1,828
  • 7
  • 29
  • 50

2 Answers2

2
I = "http://aaa:bbb@111.11.1.1:20000a"
infura_url = "https://zzzz.io/kkkk/bsc/mainnet/archive/" # fast
web3 = Web3(Web3.HTTPProvider(infura_url,request_kwargs={"proxies":{'https' : I, 'http' : I }}))
user40780
  • 1,828
  • 7
  • 29
  • 50
0

You can also use web3-proxy-providers, which is a python package for connecting to HTTP and WebSocket Json-RPC using Socks and HTTP proxies

run

pip install web3-proxy-providers

code

from web3 import Web3
from web3_proxy_providers import HttpWithProxyProvider

provider = HttpWithProxyProvider(
    endpoint_uri='https://eth-mainnet.g.alchemy.com/v2/<YourAlchemyKey>',
    proxy_url='socks5h://localhost:1080'
)
web3 = Web3(
    provider=provider,
)
print(web3.eth.block_number)

Disclaimer: I am the owner of this package https://github.com/sinarezaei/web3-proxy-providers

Sina Rezaei
  • 529
  • 3
  • 24