For a deeper look into our Elektron API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 0 1

Python WebSocket Auto-Reconnection After Login Failure

I keep getting disconnected from the WebSocket server due to login failures, and I need a solution to automatically reconnect and retry the login when this happens to maintain a stable connection. Have anyone experienced this before?

#technologywebsockets
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @AmeliaCatherine ,

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?
If so please can you click the 'Accept' text next to the appropriate reply? This will guide all community members who have a similar question.

Thanks,
AHS

@AmeliaCatherine

Hi,

Please be informed that a reply has been verified as correct in answering the question, and marked as such.

Thanks,

AHS

1 Answer

· Write an Answer
Upvote
Accepted
24.8k 54 17 14

Hello @AmeliaCatherine

### Reconnection ###

There is the reconnection logic example available on the market_price_rdpgw_service_discovery.py example as follows:

def _on_close(self, ws, close_status_code, close_msg):
    """ Called when websocket is closed """
    self.web_socket_open = False
    self.logged_in = False
    print("WebSocket Closed for " + self.session_name)


    if not self.disconnected:
        print("Reconnect to the endpoint for " + self.session_name + " after 3 seconds... ")
        time.sleep(3)
        self.connect()

However, the example is for illustrative purposes only, as mentioned in the disclaimer.

#!/usr/bin/env python
# |-----------------------------------------------------------------------------
# |            This source code is provided under the Apache 2.0 license      --
# |  and is provided AS IS with no warranty or guarantee of fit for purpose.  --
# |                See the project's LICENSE.md for details.                  --
# |            Copyright (C) 2018-2021 Refinitiv. All rights reserved.        --
# |-----------------------------------------------------------------------------

### login failures ###

Can you give me more detail about the login failures issue?

  • The login request and response error messages
  • Are you connecting to deployed ADS or RTO (on the cloud)?
  • Can you replicate the issue on demand?
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.