A wss connection problem

https://mainnet.infura.io/v3/key,
when I connect to the ETH main network with web3py, I use Web3.HTTPProvider to call the function web3.is_connected ().It returned True.

WSS://mainnet.infura.io/ws/v3/key
When I switched to Web3.WebsocketProvider, I called the function web3.is_connected () and returned False.

please help me

 w3s = Web3(Web3.WebsocketProvider('wss://mainnet.infura.io/ws/v3/***********key*******',websocket_timeout=120))
    for i in range(10):
        time.sleep(5)
        a = w3s.is_connected()
        print(a)

2 Likes

Hi @yangml,

wellcome!

For me, this:

#!/usr/bin/env python3
from web3 import Web3
import time

INFURA_API_KEY='blablabla'

w3s = Web3(Web3.WebsocketProvider('wss://mainnet.infura.io/ws/v3/'+ INFURA_API_KEY,
                                  websocket_timeout=120))
print(w3s.is_connected())

Does return true. Double check your code and let us know how you go?

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.