My test code:
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('http://192.168.1.170:8545'))
print(w3.geth.admin.node_info())
Error:
ValueError: {'code': -32601, 'message': 'the method admin_nodeInfo does not exist/is not available'}
Yet when I test web3.eth functions like :
w3.eth.getBlock('latest')
it connects to my node fine. It's just the geth methods it seemingly can't find.
Closing, it was my mistake.
Need to explicitly allow the various API's on geth's end like so "--http.api personal,eth,net,web3,admin,txpool"
i did brew install ethereum, then inside the virtual environment did
geth --http.addr https://mainnet.infura.io/v3/<#######> --http.api personal,eth,net,web3,admin,txpool
then did like this
w3.geth.personal.new_account('pass-phrase')
and still give the same error, what i did wrong? thank you
@pythonster You can't access the personal module (or any of the geth-specific or parity-specific RPC methods) via Infura. If you're trying to create an account on your local node it's best to use IPC, so you can just start geth with:
geth which enables the IPC connection by default. Then you can do w3.geth.personal....
Here are some docs you can check out:
https://web3py.readthedocs.io/en/stable/quickstart.html#provider-local-geth-node
https://web3py.readthedocs.io/en/stable/web3.eth.account.html#eth-account
https://web3py.readthedocs.io/en/stable/providers.html
@kclowes beat me to it, but will send anyway:
@pythonster you can only use geth to create new accounts if you are the one running the geth node. You're using a mix of strategies here: you installed geth locally (brew install ethereum), but infura is a remotely hosted geth node. You need to choose one or the other:
1) If geth, it takes many hours to sync, but runs on a local port, 8545 by default. You would then configure web3, e.g., w3 = Web3(HTTPProvider('http://localhost:8545')).
2) If infura, just link out to the URL they provide, e.g., w3 = Web3(HTTPProvider('https://mainnet.infura.io/<whatever>'))
Check out the docs on nodes and providers for more details.
You can also use web3 to create new accounts via web3.eth.account.create(). Note: please don't store real value in these accounts if you're just getting started. Check out something like MyCrypto to get onboarded.
@marcgarreau @kclowes Thank you, you are right! I figured out just several hours earlier that i exactly mix methods local and hosted nodes.
P.S. - For those who might be puzzled as i was - you cant just create and unlock account via geth.personal to send a transaction, you need to sign a transaction with the private key if you are using a hosted node like infura.