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

fix bug in websocketProviderV2 docs #3086

Closed
wants to merge 1 commit into from

Conversation

Vojtch159
Copy link

What was wrong?

The documentation example doesn't work.

How was it fixed?

Changed the documentation.

Todo:

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@Vojtch159
Copy link
Author

The issue exists because the iterator yields the object itself but the enter method returns the connected object.

@fselmo
Copy link
Collaborator

fselmo commented Aug 28, 2023

I don't believe this addition is necessary. If there is no connection by the time the first call is made, the connection is initiated.

async def wsV2_example():
    async for w3 in AsyncWeb3.persistent_websocket(
        WebsocketProviderV2(f"wss://mainnet.infura.io/ws/v3/{INFURA_PROJECT_ID}")
    ):
        try:
            subscription_id = await w3.eth.subscribe("newHeads")
        
            while True:
                async for response in w3.listen_to_websocket():
                    print(response)
                    ...
         
         except websockets.ConnectionClosed:
             continue

asyncio.run(wsV2_example())

Do you have issues running the above example? What is the specific issue you are seeing?

@Vojtch159
Copy link
Author

Oh, then I apologise for wasting your time here. I investigated, and when I don't connect manually my code gets stuck at creating filters (I'm subscribing to specific "logs"). At the moment I'm not sure why it happens but it seems like a different issue and I'll have to investigate it more deeply. Everything starts working perfectly fine when I do the connection manually right at the start 😕 Anyway, thank you for the response!

@Vojtch159 Vojtch159 closed this Aug 28, 2023
@Vojtch159 Vojtch159 deleted the patch-1 branch August 28, 2023 19:13
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 this pull request may close these issues.

None yet

2 participants