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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
3 2 2 7

[OMMSTREAMING_PRICING_0.12] received a closing message (cxn state=StreamCxnState.Connected, message state={'Stream': 'Closed', 'Data': 'Suspect', 'Code': 'UserAccessToAppDenied', 'Text': 'TREP authentication failed (1026, Request for token validatio

Hi Developers Community

I am running a Refinitiv web socket client, testing if it can consistently accept market data "forever"? after some long time connection is closed with error message:

[Error 400 - invalid_grant] empty error description
[OMMSTREAMING_PRICING_0.12] received a closing message (cxn state=StreamCxnState.Connected, message state={'Stream': 'Closed', 'Data': 'Suspect', 'Code': 'UserAccessToAppDenied', 'Text': 'TREP authentication failed (1026, Request for token validation failed:Authentication server did not contain "active" in response).'})

how to prevent Refinitiv connection from disconnecting while running a web socket infinitely (suppose to never stop getting market data feed)?

Thanks

Ori

refinitiv-dataplatform-eikonauthenticationtime-outdisconnectionconnection-errordeny-authentication
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.

Upvotes
Accepted
52.6k 134 44 63

@okatz

First, you can update the application to use the new version of RD Library (refinitiv-data 1.0.0b13). Then, enable debug logging in the refinitiv-data.config.json file.

 "logs": {
        "level": "debug",
        "transports": {
            "console": {
                "enabled": false
            },
            "file": {
                "enabled": true,
                "name": "refinitiv-data-lib.log"
            }
        }
    },
    "sessions": {
                

Next, share the log file when the problem occurred. Please remove the RDP credential (username and password) from the log file.

One scenario that can trigger this issue is that many applications share the same RDP credential at the same time. An RDP credential can only have one active refresh token at a time. For more information, please refer to the Limitations and Guidelines for the RDP Authentication Service article.

For example, when the first application logs in to RDP, it will get both an access and a refresh token. A fresh token will be used to get a new access token. However, if the second application logs in with the same RDP credential, the previous refresh token in the first application will be invalidated and the first application is unable to use it to get a new access token. You will see this kind of error in the log file of the first application.

[2022-06-02 09:14:41,790] - [sessions.platform.rdp.0] - [DEBUG] - [10920 - AuthManager-Thread] - [http_service] - [request] - HTTP request response 400: {"error":"invalid_grant"   } 
[2022-06-02 09:14:41,791] - [sessions.platform.rdp.0] - [DEBUG] - [10920 - AuthManager-Thread] - [refresh_token_updater] - [_request_token] - Refresh token response: {"error":"invalid_grant"   } 
[2022-06-02 09:14:41,791] - [sessions.platform.rdp.0] - [ERROR] - [10920 - AuthManager-Thread] - [refresh_token_updater] - [_do_update] - [Error 400 - invalid_grant] empty error description
[2022-06-02 09:14:41,791] - [sessions.platform.rdp.0] - [DEBUG] - [10920 - AuthManager-Thread] - [auth_manager] - [_refresh_token_update_handler] - AuthManager: Refresh token handler, event: refresh_token_bad, message: empty error description
[2022-06-02 09:14:41,791] - [sessions.platform.rdp.0] - [DEBUG] - [10920 - AuthManager-Thread] - [_session] - [_on_event] - Session._on_event(event_code=EventCode.SessionAuthenticationFailed, event_msg=empty error description, streaming_session_id=None, stream_connection_name=None)
[2022-06-02 09:14:41,791] - [sessions.platform.rdp.0] - [DEBUG] - [10920 - AuthManager-Thread] - [auth_manager] - [close] - AuthManager: close

Then, you will the following error.

[2022-06-02 09:20:14,585] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [_on_ws_error] - [OMMSTREAMING_PRICING_0.5] on_ws_error
[2022-06-02 09:20:14,585] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [_on_ws_error] - [OMMSTREAMING_PRICING_0.5] Exception: Connection to remote host was lost.
[2022-06-02 09:20:14,585] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [_on_ws_close] - [OMMSTREAMING_PRICING_0.5] on_ws_close (close_status_code=None, close_msg=None)
[2022-06-02 09:20:14,585] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [_on_ws_close] - [OMMSTREAMING_PRICING_0.5] try to reconnect over url wss://ap-southeast-1-aws-3-lrg.optimized-pricing-api.refinitiv.net:443/WebSocket in 5 secs, number of reconnections is 1, StreamCxnState.Reconnecting
[2022-06-02 09:20:19,596] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [connect] - [OMMSTREAMING_PRICING_0.5] is connecting [con]
[2022-06-02 09:20:19,596] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [connect] - [OMMSTREAMING_PRICING_0.5] connect (
    num_connect=1,
    url=wss://ap-southeast-1-aws-3-lrg.optimized-pricing-api.refinitiv.net:443/WebSocket,
    headers=['User-Agent: Python'],
    subprotocols=['tr_json2'])
[2022-06-02 09:20:20,445] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [_on_ws_open] - [OMMSTREAMING_PRICING_0.5] connected [CON]
[2022-06-02 09:20:20,445] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [_on_ws_open] - [OMMSTREAMING_PRICING_0.5] on_ws_open
[2022-06-02 09:20:20,445] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [send] - [OMMSTREAMING_PRICING_0.5] send s={"Domain": "Login", "ID": 5, "Key": {"NameType": "AuthnToken", "Elements": {"AuthenticationToken": "...", "ApplicationId": "256", "Position": "192.168.0.184/WIN-2NOVD7CLMV1"}}}
[2022-06-02 09:20:20,885] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [_on_ws_message] - [OMMSTREAMING_PRICING_0.5] on_ws_message [{"ID":5,"Type":"Status","Domain":"Login","Key":{"NameType":5,"Elements":{"AuthenticationErrorCode":1026,"AuthenticationErrorText":"Request for token validation failed:Authentication server did not contain \"active\" in response"}},"State":{"Stream":"Closed","Data":"Suspect","Code":"UserAccessToAppDenied","Text":"TREP authentication failed (1026, Request for token validation failed:Authentication server did not contain \"active\" in response)."}}]
[2022-06-02 09:20:20,885] - [sessions.platform.rdp.0] - [ERROR] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [omm_stream_connection] - [_handle_login_message] - [OMMSTREAMING_PRICING_0.5] received a closing message (cxn state=StreamCxnState.Connected, message state={'Stream': 'Closed', 'Data': 'Suspect', 'Code': 'UserAccessToAppDenied', 'Text': 'TREP authentication failed (1026, Request for token validation failed:Authentication server did not contain "active" in response).'})
[2022-06-02 09:20:20,885] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [dispose] - [OMMSTREAMING_PRICING_0.5] is disposing [d]
[2022-06-02 09:20:20,885] - [sessions.platform.rdp.0] - [DEBUG] - [12348 - ThreadOMMSTREAMING_PRICING_0.5] - [stream_connection] - [send] - [OMMSTREAMING_PRICING_0.5] send s={"Domain": "Login", "ID": 5, "Type": "Close"}


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.

Hello @okatz

Just want to add more information to my colleague's answer about multiple applications sharing the same RDP credential.

If you use a single RDP credential with multiple sessions/applications, the applications may encounter an error when an access token expires or when applications try to refresh an access token (as explained by my colleague above). I suggest you use multiple credentials if you want to run multiple applications/sessions.

Upvote
16.7k 31 9 12

Hello @okatz

This "TREP authentication failed (1026, Request for token validation failed:Authentication server did not contain \"active\" in response)." error message is generated from the RTO WebSocket server when it receives an expired Access Token in the WebSocket JSON login request message from the application.

Does the application send an active (and valid) Access Token to the RTO server?

Please note that the Access Token always expires in 600 seconds (based on the RDP Auth response’s “expires_in” JSON value). The application needs to maintain the Access Token session and WebSocket connection with the following steps:

  1. renew the Access Token by sending the HTTP REST request to the RDP Auth service (with "refresh_token" grant type) to get a new refresh and Access Tokens before the Access Token expires.
  2. Re-send a Login request to the Refinitiv Real-Time - Optimized server using the new obtained Access Token

You can find more detail on the Connect to Refinitiv Real-Time - Optimized tutorial page. The example code that shows a connection logic is available for Java, C#, and Python programming languages at https://github.com/Refinitiv/websocket-api/tree/master/Applications/Examples/RDP page (please ignore the Go example, it is for a different logic).

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.

I could not find a simple explanation how to handle and refresh expiration token when working with web sockets. Examples are with HTTP. I try to reduce footprint of additional libraries and http/s coding. Is there a simple method to just refresh the token before expiration without too match integration and coding?
Upvotes
16.7k 31 9 12

Hello @okatz

I am suspecting that you are using the Refinitiv Data Library (RD) ease-of-use API, please confirm my understanding.

If you are using the RD library, can you give us more detail?

  • Which library edition you are using (Python or .Net)?
  • The library and compiler versions
  • Can you replicate the issue with the library example?
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.

import refinitiv.data as rd
from refinitiv.data.content import pricing


python version on development windows 10 workstation:

(py38q) E:\workQuant\MRMTFeedRT>python -V
Python 3.8.12
refinitiv-data                1.0.0b10


and with production ubuntu 20.04 server:

(base) ori_kovacsi_katz@prod:~$ conda activate kx1
(kx1) ori_kovacsi_katz@prod:~$ python -V
Python 3.9.7
(kx1) ori_kovacsi_katz@prod:~$
refinitiv-data             1.0.0b9


connecting client:

        rd.load_config('E:/Configuration/refinitiv-data.config.json')
        #rd.load_config('/Configuration/refinitiv-data.config.json')
        rd.open_session()
        self.theWebSocket = rd.content.pricing.Definition(['BTCc1','BTCc2','BTCc3','BTCc4','BTCc5','BTCc6','BTCc7','BTCc8','BTCc9','QBTCu.TO','QETHu.TO'], fields=['BID', 'ASK', 'QUOTIM', 'QUOTIM_MS', 'ORDER_SIDE', 'ORDER_PRC', 'ORDER_SIZE', 'BID_SIZE', 'ASK_SIZE']).get_stream()
        self.theWebSocket.on_refresh(self.handle_refresh)
        self.theWebSocket.on_update(self.handle_update_wrapper)
        self.theWebSocket.on_status(self.handle_status)
        self.theWebSocket.open()