Web3.py – How to Fix AttributeError: type object ‘Web3’ has no attribute ‘eth’

pythonweb3.py

I am working on a smart contract integrated Django project. But When I try to check the account using Web3.eth.accounts get an error,

AttributeError: type object 'Web3' has no attribute 'eth'

Other coding part given below,

from web3 import Web3
import time
import sys
from .auth_contract_connection import contract_address,abi
sys.path.append('../')
from connection import connection

con=Web3(Web3.HTTPProvider("HTTP://127.0.0.1:7545"))

how I slow this?

Best Answer

You need to call what was initialised as Web3. in your case, con

con.eth.accounts

alternatively use the standard web3 or w3

web3 = Web3(Web3.HTTPProvider("HTTP://127.0.0.1:7545"))

then your code will work with web.eth.accounts