Cannot prepare connection OMMStreamConnection when running in Pycharm IDE vs Codebook

je_east
je_east Newcomer

I run the following code in codebook and it’s fine:

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

contract = 'CL'

rd.open_session()

ice_oil = ['LCO', 'LGO']

chain = pricing.chain.Definition(name=f"0#/{contract}:").get_stream()

chain.open(with_updates=False)

chain.close()

if contract in ice_oil:

    tkrs = list(chain.constituents[1:13])

else:

    tkrs = list(chain.constituents[:12])

print(tkrs)

rd.close_session()

and get the following response:

['/CLH25', '/CLJ25', '/CLK25', '/CLM25', '/CLN25', '/CLQ25', '/CLU25', '/CLV25', '/CLX25', '/CLZ25', '/CLF26', '/CLG26']

which is as expected.

However, when I run this from pycharm IDE, I get the following error:

Traceback (most recent call last):

  File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.3\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode

    coro = func()

           ^^^^^^

  File "<input>", line 5, in <module>

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\_basestream.py", line 72, in open

    self._stream.open(with_updates=with_updates)

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\_basestream.py", line 166, in open

    return self.state.open(*args, **kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\states\_basestream_states.py", line 51, in open

    return self.stream.do_open(*args, **kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\_basestream.py", line 183, in do_open

    self._do_open(*args, **kwargs)

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\content\pricing\chain\_stream.py", line 230, in _do_open

    self.add(name).open(with_updates=with_updates)

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\_basestream.py", line 166, in open

    return self.state.open(*args, **kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\states\_basestream_states.py", line 51, in open

    return self.stream.do_open(*args, **kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\_basestream.py", line 183, in do_open

    self._do_open(*args, **kwargs)

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\_omm_stream.py", line 317, in _do_open

    super()._do_open(*args, **kwargs)

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\_stream.py", line 79, in _do_open

    self.cxn = stream_cxn_cache.get_cxn(self.session, self.details)

               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "C:\Users\je\.venv\Lib\site-packages\refinitiv\data\delivery\_stream\_stream_cxn_cache.py", line 127, in get_cxn

    raise ConnectionError(f"Cannot prepare connection {cxn}")

ConnectionError: Cannot prepare connection OMMStreamConnection

                                name             : ThreadOMMSTREAMING_CHAINS_0.1

                                state            : StreamCxnState.Disposed

                                subprotocol      : tr_json2

                                is_auto_reconnect: True

                                can_reconnect    : False

                                num_attempt      : 0

What is strange is that if I call the following in pycharm, it works fine. I know it’s a different query but it’s still using Refinitiv.data.content library:

import refinitiv.data as rd
from refinitiv.data.content import historical_pricing
from refinitiv.data.content.historical_pricing import Intervals

rd.open_session()
response = historical_pricing.summaries.Definition(universe= ['1067651MLNG', '1067651MSHT', '1067651RLNG', '1067651RSHT'],
interval=Intervals.DAILY,
count=4,fields=["TRDPRC_1"]).get_data()

cot_df = response.data.df

Has anyone experienced this connection error when running calls from a third party app please?
is there a particular endpoint for this library that would need to be configured for firewalls maybe?

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @je_east

    Thank you for reaching out to us.

    The following log indicates tha the library can't establish a websocket connection to the API proxy.

    ConnectionError: Cannot prepare connection OMMStreamConnection

    name : ThreadOMMSTREAMING_CHAINS_0.1

    state : StreamCxnState.Disposed

    subprotocol : tr_json2

    is_auto_reconnect: True

    can_reconnect : False

    num_attempt : 0

    Please refer to this discussion.

  • je_east
    je_east Newcomer

    Thanks for your quick reply. Yes, I agree it's failing to establish the connection. But how comes the my data api proxy status is 'Ready' and I can pull data from the 'historical_pricing' library also included in refinitiv-data.content, but not 'pricing'. Does it pull from a different end-point?

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    Correct. They use different endpoints.

    Historical pricing uses the REST API while the stream pricing uses the Websocket connection.

    Please enable the debug log, as mentioned in this discussion. We may be able to see the problem in the debug log.

  • je_east
    je_east Newcomer

    Thank you - please see the log (-1123-38168-)attached. I've also included a successful request log (-1121-44004-) for comparison

  • je_east
    je_east Newcomer

    Apologies, incorrect log attached. Please find correct file attached now (-1239-61168-)

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @je_east

    That is strange. I didn't see any errors in the 20250211-1123-38168-lseg-data-lib,log file. The last line is:


    [2025-02-11T11:23:09.976297+00:00] - [sessions.desktop.workspace.0] - [DEBUG] - [52228 - MainThread] - [_session] - [open] - Opened session
    [2025-02-11T11:23:10.111451+00:00] - [sessions.desktop.workspace.0] - [DEBUG] - [52228 - MainThread] - [_basestream] - [transition_to] - StreamingChain id=0 name='0#/CL:' state=UnopenedBaseStreamSt inited

    I ran the code on my machine and it can get the data properly. The log is:

    [2025-02-11T19:15:25.243316+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [_session] - [open] - Opened session
    [2025-02-11T19:16:05.214486+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [_basestream] - [transition_to] - StreamingChain id=0 name='0#/CL:' state=UnopenedBaseStreamSt inited
    [2025-02-11T19:16:05.215490+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [_basestream] - [open] - StreamingChain id=0 name='0#/CL:' state=UnopenedBaseStreamSt open kwargs={'with_updates': False}
    [2025-02-11T19:16:05.217481+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [_basestream] - [transition_to] - StreamingChain id=0 name='0#/CL:' transition UnopenedBaseStreamSt -> OpeningBaseStreamSt
    [2025-02-11T19:16:05.218489+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [_basestream] - [transition_to] - _OMMStream id=5 name='0#/CL:' state=UnopenedOMMStreamSt inited
    [2025-02-11T19:16:05.219491+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [_basestream] - [open] - StreamingChain id=0 name='0#/CL:' [_OMMStream id=5 name='0#/CL:'] state=UnopenedOMMStreamSt open kwargs={'with_updates': False}
    [2025-02-11T19:16:05.221494+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [_basestream] - [transition_to] - StreamingChain id=0 name='0#/CL:' [_OMMStream id=5 name='0#/CL:'] transition UnopenedOMMStreamSt -> OpeningOMMStreamSt
    [2025-02-11T19:16:05.222493+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [_stream] - [_do_open] - StreamingChain id=0 name='0#/CL:' [_OMMStream id=5 name='0#/CL:'] request cxn
    [2025-02-11T19:16:05.224493+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [http_service] - [build_request] - HTTP Request id 2
    	url = http://localhost:9001/api/rdp/streaming/pricing/v1/
    	method = GET
    	headers = {'Authorization': 'Bearer .', 'x-tr-applicationid': '…'}
    
    [2025-02-11T19:16:05.225493+07:00] - [RetryTransportBase] - [DEBUG] - [77992 - MainThread] - [_retry_transport] - [_handle_request] - Sending request to http://localhost:9001/api/rdp/streaming/pricing/v1/
    [2025-02-11T19:16:07.271588+07:00] - [sessions.desktop.workspace.0] - [DEBUG] - [77992 - MainThread] - [http_service] - [request] - HTTP Response id 2
    	status_code = 200
    	text = {"services":[{"dataFormat":["tr_json2"],"endpoint":"localhost/api/rdp/streaming/pricing/v1/WebSocket","location":["local"],"port":9001,"provider":"local","transport":"websocket"}]}
    [2025-02-11T19:16:07.271588+07:00] - [rd.stream-factory] - [DEBUG] - [77992 - MainThread] - [_stream_factory] - [create_stream_cxn] -  + Created: 
    	cxn    : OMMStreamConnection
    		name             : ThreadOMMSTREAMING_CHAINS_0.0
    		state            : StreamCxnState.Initial
    		subprotocol      : tr_json2
    		is_auto_reconnect: True
    		can_reconnect    : True
    		num_attempt      : 0
    	config : DesktopStreamCxnConfig
    

    Did you still see the following error?

    ConnectionError: Cannot prepare connection OMMStreamConnection

    name : ThreadOMMSTREAMING_CHAINS_0.1

    state : StreamCxnState.Disposed

    subprotocol : tr_json2

    is_auto_reconnect: True

    can_reconnect : False

    num_attempt : 0

    Please try to run the following code to verify the connection.

    import requests
    headers={
        "Connection":"Upgrade",
        "Upgrade":"websocket",
        "Sec-WebSocket-Key":"dGhlIHNhbXBsZSBub25jZQ==",
        "Sec-WebSocket-Version": "13",
        "Sec-WebSocket-Protocol":"tr_json2"
    }
    res = requests.get("http://localhost:9000/api/rdp/streaming/pricing/v1/WebSocket", headers=headers)
    print(res)
    print(res.content)
    
    image.png

    The port 9000 may be changed. Please check the debug log for the port (http://localhost:9000/api/handshake)

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @je_east

    Okay. I can establish a WebSocket connection but it can't login to the server.

    [2025-02-11T12:39:26.324439+00:00] - [sessions.desktop.workspace.0] - [DEBUG] - [37996 - ThreadOMMSTREAMING_CHAINS_0.0] - [stream_connection] - [_run_websocket_listener] - [OMMSTREAMING_CHAINS_0.0] connect
    num_attempt : 0
    url : ws://localhost:9000/api/rdp/streaming/pricing/v1/WebSocket
    headers : ['User-Agent: Python', 'x-tr-applicationid: DEFAULT_WORKSPACE_APP_KEY', 'Authorization: Bearer …']
    cookies : None
    transport : websocket
    subprotocols: ['tr_json2']
    [2025-02-11T12:39:28.524514+00:00] - [sessions.desktop.workspace.0] - [DEBUG] - [37996 - ThreadOMMSTREAMING_CHAINS_0.0] - [stream_connection] - [_on_ws_open] - [OMMSTREAMING_CHAINS_0.0] on_ws_open
    [2025-02-11T12:39:28.856998+00:00] - [sessions.desktop.workspace.0] - [DEBUG] - [37996 - ThreadOMMSTREAMING_CHAINS_0.0] - [stream_connection] - [_on_ws_open] - [OMMSTREAMING_CHAINS_0.0] send login message {'Domain': 'Login', 'ID': 2, 'Key': {'Elements': {'AppKey': 'DEFAULT_WORKSPACE_APP_KEY', 'Authorization': 'Bearer …', 'ApplicationId': '256', 'Position': '127.0.0.1/EAL-JE'}}}
    [2025-02-11T12:39:29.530168+00:00] - [sessions.desktop.workspace.0] - [DEBUG] - [37996 - ThreadOMMSTREAMING_CHAINS_0.0] - [stream_connection] - [_on_message] - [OMMSTREAMING_CHAINS_0.0] on_ws_message [{"ID": 2, "State": {"Code": "ConnectionError", "Data": "Suspect", "Stream": "Closed", "Text": "Cannot establish connection to the platform"}, "Type": "Status"}]
    [2025-02-11T12:39:29.804573+00:00] - [sessions.desktop.workspace.0] - [DEBUG] - [37996 - ThreadOMMSTREAMING_CHAINS_0.0] - [omm_stream_connection] - [_handle_login_message] - [OMMSTREAMING_CHAINS_0.0] received a closing message: state=StreamCxnState.Connecting, message={'ID': 2, 'State': {'Code': 'ConnectionError', 'Data': 'Suspect', 'Stream': 'Closed', 'Text': 'Cannot establish connection to the platform'}, 'Type': 'Status'}

    The library connects to the component called the Data API Proxy and then the Data API Proxy connects to the Platform. There is a connection problem between the Data API Proxy and the Platform.

    You need to enable the debug log in Eikon or Workspace and then share the Data API Proxy log file, as mentioned in this article.

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @je_east

    I checked the log file and found several errors.

    2025-02-07T08:23:59.937Z|error|[console](api)  [ERROR] API Proxy::RdpAccessTokenProvider - RDP token retrieve error:  
    …
    2025-02-07T08:23:59.937Z|error|[console](api) unable to get local issuer certificate 
    

    Typically, the "unable to get local issuer certificate" error relates to security software, proxy, or firewall.

    This is out of the library scope. Please contact our helpdesk via MyAccount to verify this log or your network team to verify this issue.