Not getting connected to Websocket2.0


  • from SmartApi.smartConnect import SmartConnect
    from SmartApi.smartWebSocketV2 import SmartWebSocketV2
    from pyotp import TOTP
    import login as l

    obj=SmartConnect(api_key=l.api_key)
    data=obj.generateSession(clientCode=l.user_name,password=l.password,totp=TOTP(l.token).now())
    Feed_token=obj.getfeedToken()
    Auth_token=data['data']['jwtToken']
    prof=obj.getProfile(data['data']['refreshToken'])

    sws=SmartWebSocketV2(auth_token=Auth_token,api_key=l.api_key,client_code=l.user_name,feed_token=Feed_token)

    def on_open(wsapp):
    print("open")
    sws.subscribe(correlation_id="stream_1",mode=3,token_list=[{"exchangeType": 1, "tokens": "1594"}])

    def on_data(wsapp,message):
    print("Tick : {}".format(message))

    def on_error(wsapp,error):
    print(error)

    sws.on_open=on_open
    sws.on_data=on_data
    sws.on_error=on_error

    sws.connect()

    -----------------------CODE------------------------------
    On open
    [E 240129 15:00:23 smartWebSocketV2:218] Error occurred during subscribe: 'str' object has no attribute 'extend'
    [W 240129 15:00:23 smartWebSocketV2:326] Attempting to resubscribe/reconnect (Attempt 1)...
    On open
    [E 240129 15:00:44 smartWebSocketV2:218] Error occurred during subscribe: 'str' object has no attribute 'extend'

    Connection closed
    [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.

    Connection closed
    [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.

    Connection closed
    [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.

    Connection closed
    [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.

    Connection closed
    [W 240129 15:00:45 smartWebSocketV2:350] Connection closed due to max retry attempts reached.


  • @Moderator_2 I am still getting the same error anyway. I have just initiated one socket.


  • Hi @Manish-Choudhary

    Apologies for delayed response.
    Please reverify on the no of connection, we have limit of three connection Websocket smartAPI, if total connection per client count reached 3 all new connection will be blocked.

    Thanks & Regards,
    SmartAPI team