弃用警告:在 python3
DeprecationWarning: in python3
在 python3.6 中导入 web3 库时
from web3.auto import w3
我收到一大堆警告,例如:
.local/lib/python3.6/site-packages/eth_utils/string.py:23:
DeprecationWarning: The force_bytes
function has been deprecated and will be removed in a subsequent release of the eth-utils library. UTF8 cannot encode some byte values in the 0-255 range which makes naive coersion between bytes and text representations impossible without explicitly declared encodings.
"declared encodings.".format(fn.__name__)
还有很多这样的。
我该如何解决?
web3.auto 不再包含在 web3 库中,它已从新的稳定库中删除,因此在最新稳定版本的 web3 库中,您必须手动提供提供者。
提供商是 web3 连接到区块链的方式。 Web3 库附带以下 built-in 提供程序,应该适合大多数正常用例。
- web3.HTTPProvider 用于连接到基于 http 和 https 的 JSON-RPC 服务器。
- web3.IPCProvider 用于连接基于 IPC 套接字的 JSON-RPC 服务器。
HTTPProvider 获取可以找到服务器的完整 URI。对于本地开发,这类似于 http://localhost:8545.
IPCProvider 采用可以找到 IPC 套接字的文件系统路径。如果未提供参数,它将使用您操作系统的默认路径。
>>> from web3 import Web3, HTTPProvider, IPCProvider
# Note that you should create only one RPCProvider per
# process, as it recycles underlying TCP/IP network connections between
# your process and Ethereum node
>>> web3 = Web3(HTTPProvider('http://localhost:8545'))
# or for an IPC based connection
>>> web3 = Web3(IPCProvider())
更多信息请阅读docs
注意:安装web3库时安装最新的。
相反,你正在做的事情是这样的:
from web3 import Web3, HTTPProvider
# For HTTPProvider
w3 = Web3(HTTPProvider('http://localhost:8545.'))
希望对您有所帮助! :)
在 python3.6 中导入 web3 库时
from web3.auto import w3
我收到一大堆警告,例如:
.local/lib/python3.6/site-packages/eth_utils/string.py:23:
DeprecationWarning: Theforce_bytes
function has been deprecated and will be removed in a subsequent release of the eth-utils library. UTF8 cannot encode some byte values in the 0-255 range which makes naive coersion between bytes and text representations impossible without explicitly declared encodings.
"declared encodings.".format(fn.__name__)
还有很多这样的。 我该如何解决?
web3.auto 不再包含在 web3 库中,它已从新的稳定库中删除,因此在最新稳定版本的 web3 库中,您必须手动提供提供者。 提供商是 web3 连接到区块链的方式。 Web3 库附带以下 built-in 提供程序,应该适合大多数正常用例。
- web3.HTTPProvider 用于连接到基于 http 和 https 的 JSON-RPC 服务器。
- web3.IPCProvider 用于连接基于 IPC 套接字的 JSON-RPC 服务器。
HTTPProvider 获取可以找到服务器的完整 URI。对于本地开发,这类似于 http://localhost:8545.
IPCProvider 采用可以找到 IPC 套接字的文件系统路径。如果未提供参数,它将使用您操作系统的默认路径。
>>> from web3 import Web3, HTTPProvider, IPCProvider
# Note that you should create only one RPCProvider per
# process, as it recycles underlying TCP/IP network connections between
# your process and Ethereum node
>>> web3 = Web3(HTTPProvider('http://localhost:8545'))
# or for an IPC based connection
>>> web3 = Web3(IPCProvider())
更多信息请阅读docs
注意:安装web3库时安装最新的。 相反,你正在做的事情是这样的:
from web3 import Web3, HTTPProvider
# For HTTPProvider
w3 = Web3(HTTPProvider('http://localhost:8545.'))
希望对您有所帮助! :)