You need to enable JavaScript to run this app. 如何在web3py中为HTTPProvider配置使用代理服务器?
优惠活动
大模型
产品
解决方案
定价
更多

如何在web3py中为HTTPProvider配置使用代理服务器?

Web3Py 配置代理访问节点的方法

你可以通过 Web3.HTTPProvider 的 request_kwargs 参数,向底层的requests库传递代理配置即可,修改后的代码示例如下:

from web3 import Web3

infura_url = "https://node.node/asdasdasdasdasd/bsc/mainnet/archive/" # fast
# 配置代理规则,http/https请求均走指定代理
proxies = {
    "http": "http://321.123.121.123:8081",
    "https": "http://321.123.121.123:8081"
}
# 实例化Web3时传入代理配置
web3 = Web3(Web3.HTTPProvider(
    infura_url,
    request_kwargs={"proxies": proxies}
))

如果你的代理需要身份校验,将代理地址改为 http://用户名:密码@321.123.121.123:8081 格式即可。

内容的提问来源于stack exchange,提问作者user40780

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 03:48:01