DeprecationWarning: in python3

Question:

while importing the web3 library in python3.6

from web3.auto import w3

i get whole a bunch of warnings like:

.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__)

and many more like this.

How can I resolve this?

Asked By: user8421208

||

Answers:

The web3.auto is no longer included in web3 library it is removed from new and stable library, so in the latest and stable version of web3 library you have to manually provide the provider.
Providers are how web3 connects to the blockchain. The Web3 library comes with a the following built-in providers that should be suitable for most normal use cases.

  1. web3.HTTPProvider for connecting to http and https based JSON-RPC servers.
  2. web3.IPCProvider for connecting to ipc socket based JSON-RPC servers.

The HTTPProvider takes the full URI where the server can be found. For local development this would be something like http://localhost:8545.

The IPCProvider takes the filesystem path where the IPC socket can be found. If no argument is provided it will use the default path for your operating system.

>>> 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())

For more information please read docs

Note: when install web3 library install the latest one.
and instead what you are doing done something like:

from web3 import Web3, HTTPProvider
# For HTTPProvider
w3 = Web3(HTTPProvider('http://localhost:8545.'))
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.