【自动化测试】web3py 连接 goerli

web3py 连接 goerli

直接使用库里方法

python 复制代码
if __name__ == '__main__':
    from web3.auto.infura.goerli import w3
    w3.eth.get_balance(get_address_by_private_key(os.getenv("AAA_KEY")))
  • error info:
text 复制代码
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 401

换一种方式

python 复制代码
from web3 import Web3, HTTPProvider
connection = Web3(HTTPProvider('https://goerli.infura.io/v3/<API-KEY>'))
print ("Latest Ethereum block number", connection.eth.blockNumber)

但没有 api-key 的话

shell 复制代码
Traceback (most recent call last):
  File "/Users/apple/github/qadev-py-scripts/test-web3/spider_eth.py", line 26, in <module>
    from web3.auto.infura.goerli import w3
  File "/Users/apple/miniconda/envs/web3/lib/python3.7/site-packages/web3/auto/infura/__init__.py", line 13, in <module>
    _infura_url = build_infura_url(INFURA_MAINNET_DOMAIN)
  File "/Users/apple/miniconda/envs/web3/lib/python3.7/site-packages/web3/auto/infura/endpoints.py", line 55, in build_infura_url
    key = load_api_key()
  File "/Users/apple/miniconda/envs/web3/lib/python3.7/site-packages/web3/auto/infura/endpoints.py", line 35, in load_api_key
    "No Infura Project ID found. Please ensure "
web3.exceptions.InfuraKeyNotFound: No Infura Project ID found. Please ensure that the environment variable WEB3_INFURA_PROJECT_ID is set.

从报错看的需要一个 WEB3_INFURA_PROJECT_ID, 去申请一个 infura id

问题解决

资料

相关推荐
木西1 天前
React Native DApp 开发全栈实战·从 0 到 1 系列(兑换-合约部分)
web3·智能合约·solidity
全干engineer2 天前
区块链web3项目实战-Truffle petshop
web3·区块链
Armonia生态2 天前
Armonia Mall超级数字生态WEB3商城的引领者
web3·armonia-mall
alex1003 天前
【一天一个Web3概念】Web3.0赛道分析:新一轮技术浪潮下的机遇与挑战
web3
Web3_Daisy4 天前
克隆代币 + 捆绑开盘:多链环境下的低成本发币玩法
人工智能·web3·区块链·比特币
清 晨4 天前
Web3:去中心化网络指南
web3·去中心化·区块链·facebook·tiktok·instagram·clonbrowser
清 晨4 天前
Web3.0应用成功的诀窍
web3·互联网·facebook·tiktok·instagram·指纹浏览器·clonbrowser
moz与京5 天前
【面试向】热门技术话题(上)
人工智能·物联网·机器学习·面试·web3·区块链·元宇宙
木西5 天前
React Native DApp 开发全栈实战·从 0 到 1 系列(永续合约交易-前端部分)
react native·web3·智能合约
OpenBuild.xyz6 天前
Web3 开发者周刊 66 | 重新审视L2:跨链桥与定序器背后的信任裂痕
web3·区块链·业界资讯·周报·数字货币