2

I am trying to subscribe to pending transactions on the Ethereum blockchain using this tutorial from Infura: https://docs.infura.io/tutorials/ethereum/subscribe-to-pending-transactions

When I try to execute the .py file in Terminal it reads:

''' websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 401 '''

I am very unfamiliar with Python and Infura websockets. What is the problem with my code and how can I correct it?

1
  • Hi, make sure to add the WebSocket endpoint in the variable infura_ws_url. It worked as expected for me! Aug 3 at 23:22

1 Answer 1

1

GM, Developer Relations Lead at Chainstack here.

Assuming you're using the full code snippet provided in that article, this error stems from an attempt to open a WebSocket connection on an invalid endpoint- this most likely means that the URL you're using in async with connect(URL) as ws: is not a valid WebSocket endpoint~ which could be the result of not using the right endpoint authentication (the string that goes into <YOUR_API_KEY>)

As a side note, the code provided in this article works for me with a Chainstack Elastic Node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.