Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set multiple providers #1701

Closed
nolash opened this issue Aug 6, 2020 · 3 comments · Fixed by #1743
Closed

Cannot set multiple providers #1701

nolash opened this issue Aug 6, 2020 · 3 comments · Fixed by #1743

Comments

@nolash
Copy link

nolash commented Aug 6, 2020

  • Version: 5.12.0
  • Python: 3.8.4
  • OS: linux 5.7.0
  • pip freeze output
http://gateway.ethswarm.org/files/aaa5b1f479fa918270eac50c705de8bd21512adffbe22f64ce2765e621721014

wtr: https://web3py.readthedocs.io/en/stable/web3.main.html#providers

(venv) web3 $ cat <<EOF | python
> from web3 import Web3, WebsocketProvider, IPCProvider
> 
> w3 = Web3()
> w3.setProviders([IPCProvider('/tmp/foo.ipc'), WebsocketProvider('ws://127.0.0.1:8546')])
> EOF
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
AttributeError: 'Web3' object has no attribute 'setProviders'
$ cat <<EOF | python
> from web3 import Web3, WebsocketProvider, IPCProvider
> 
> w3 = Web3([IPCProvider('/tmp/foo.ipc'), WebsocketProvider('ws://127.0.0.1:8546')])
> print(w3.eth.blockNumber)
> EOF
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/home/lash/src/tests/py/web3/venv/lib/python3.8/site-packages/web3/eth.py", line 149, in blockNumber
    return self.web3.manager.request_blocking(RPC.eth_blockNumber, [])
  File "/home/lash/src/tests/py/web3/venv/lib/python3.8/site-packages/web3/manager.py", line 149, in request_blocking
    response = self._make_request(method, params)
  File "/home/lash/src/tests/py/web3/venv/lib/python3.8/site-packages/web3/manager.py", line 124, in _make_request
    request_func = self.provider.request_func(
AttributeError: 'list' object has no attribute 'request_func'
$ cat <<EOF | python
> from web3 import Web3, WebsocketProvider, IPCProvider
> 
> w3 = Web3([WebsocketProvider('ws://127.0.0.1:8546'), IPCProvider('/tmp/foo.ipc')])
> print(w3.eth.blockNumber)
> EOF
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/home/lash/src/tests/py/web3/venv/lib/python3.8/site-packages/web3/eth.py", line 149, in blockNumber
    return self.web3.manager.request_blocking(RPC.eth_blockNumber, [])
  File "/home/lash/src/tests/py/web3/venv/lib/python3.8/site-packages/web3/manager.py", line 149, in request_blocking
    response = self._make_request(method, params)
  File "/home/lash/src/tests/py/web3/venv/lib/python3.8/site-packages/web3/manager.py", line 124, in _make_request
    request_func = self.provider.request_func(
AttributeError: 'list' object has no attribute 'request_func'

Control:

$ cat <<EOF | python 
> from web3 import Web3, WebsocketProvider, IPCProvider
> 
> w3 = Web3(WebsocketProvider('ws://127.0.0.1:8546'))
> print(w3.eth.blockNumber)
> EOF
7439790
$ socat UNIX-LISTEN:/tmp/foo.ipc - &
[1] 624556
(venv) web3 $ cat <<EOF | python
> from web3 import Web3, WebsocketProvider, IPCProvider
> 
> w3 = Web3(IPCProvider('/tmp/foo.ipc'))
> print(w3.eth.blockNumber)
> EOF
{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 0}
@kclowes
Copy link
Collaborator

kclowes commented Aug 6, 2020

Sorry for the confusion. We removed the functionality to set multiple providers on one web3 instance. IIRC it was because there was no logic to be able to cycle through providers so it didn't really seem to make sense to allow multiple providers. Apparently the docs didn't get updated though, sorry about that. One workaround is to have two different web3 instances, each with a different provider though if you want. I'll leave this open to make the doc change.

@sk33z3r
Copy link

sk33z3r commented May 5, 2023

Apologies for necro-bumping this issue, but there's still an inconsistency in the docs that sent me on a 2-hour long goose-chase until I eventually found this ticket.

https://web3py.readthedocs.io/en/stable/ens_overview.html

Step 2 under Setup says:
2. Specify an instance or list of Providers

"or list" gave me the impression I could specify multiple providers as a redundancy kinda solution in case one provider was down. I see now I will have to do that checking myself, but if that line could updated it would save some future confusion.

@pacrob
Copy link
Contributor

pacrob commented May 9, 2023

Thanks for the note, @sk33z3r , and for introducing the term "necro-bumping" to my vocabulary. Fix incoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants