Connection problem with 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()
    

    ------------------------------output---------------------------------

    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 placed the websocket python file locally and importing it. Now it's working fine. Thank you. Didn't really know why it worked? Any comments?


  • @Moderator_2 I am getting same error kindly provide any solution for that. Same error in laptop
    It easy to subscribe 2, 3 5 ... token but how to append 200 token ??

    Here is screenshot of error,

    ![1_1709309555278_Screenshot_20240301-123231_Pydroid 3.jpg](Uploading 100%) ![0_1709309555209_Screenshot_20240301-143218_Pydroid 3.jpg](Uploading 100%)



  • @Moderator_2
    I am getting same error,


  • Hi @jaideep-siddula

    Kindly share which SDK version is consumed and error snapshot if possible to analyze issue from our end.

    Regards,
    SmartAPI team


  • I'm getting "Attempting to resubscribe/reconnect for the past few days " . Any help is aprreciated.

    Thanks in advance.


  • @Moderator_2 Hi this issue is not about having more than three connections. This issue comes even with only one connection with only one token subscribed. And this happens lot of time.
    Not only that, even if you unsubscribe the token using sws.unsubscribe(correlation_id, mode, token_list) and sws.close_connection(), it doesn't close and gets resubscribed.


  • 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