I am trying to connect to the Refinitiv Realtime Optimized platform in AWS using websockets in python.
I am using the market_price_rdpgw_service_discovery.py example from https://github.com/Refinitiv/websocket-api/tree/master/Applications/Examples/RDP/python#windowslinuxmacos
The HTTP requests for service discovery work and I can setup a token but the websocket connection fails:
Sending Refinitiv Data Platform service discovery request to https://api.refinitiv.com/streaming/pricing/v1/
Refinitiv Data Platform Service discovery succeeded. RECEIVED:
....
Connecting to WebSocket wss://eu-west-1-aws-3-sm.optimized-pricing-api.refinitiv.net:443/WebSocket for session1...
Traceback (most recent call last):
File "/home/tom/anaconda3/envs/rrt_client/lib/python3.8/site-packages/websocket/_app.py", line 312, in run_forever
self.sock.connect(
File "/home/tom/anaconda3/envs/rrt_client/lib/python3.8/site-packages/websocket/_core.py", line 248, in connect
self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options),
File "/home/tom/anaconda3/envs/rrt_client/lib/python3.8/site-packages/websocket/_http.py", line 121, in connect
sock = _ssl_socket(sock, options.sslopt, hostname)
File "/home/tom/anaconda3/envs/rrt_client/lib/python3.8/site-packages/websocket/_http.py", line 256, in _ssl_socket
sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
File "/home/tom/anaconda3/envs/rrt_client/lib/python3.8/site-packages/websocket/_http.py", line 231, in _wrap_sni_socket
return context.wrap_socket(
File "/home/tom/anaconda3/envs/rrt_client/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/home/tom/anaconda3/envs/rrt_client/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/home/tom/anaconda3/envs/rrt_client/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1131)
EOF occurred in violation of protocol (_ssl.c:1131) for session1
WebSocket Closed for session1
I've tried disabling all SSL verification and fixing the version to TSL 1.2 but still get the same error on handshake with the socket.
def connect(self):
# Start websocket handshake
ws_address = "wss://{}/WebSocket".format(self.host)
print("Connecting to WebSocket " + ws_address + " for " + self.session_name + "...")
self.web_socket_app = websocket.WebSocketApp(ws_address,
on_message=self._on_message,
on_error=self._on_error,
on_close=self._on_close,
on_open=self._on_open,
subprotocols=['tr_json2'])
sslopt = {
'check_hostname': False,
"verify_mode": ssl.CERT_NONE,
"cert_reqs": ssl.CERT_NONE,
"ssl_version": ssl.PROTOCOL_TLSv1_2,
}
wst = threading.Thread(target=self.web_socket_app.run_forever, kwargs={'sslopt': sslopt})
wst.start()
Here are some of the relevant library version:
pip list |grep 'socket\|request\|http\|cert\|url'
certifi 2021.10.8
ndg-httpsclient 0.5.1
requests 2.22.0
requests-toolbelt 0.9.1
urllib3 1.25.11
websocket-client 1.1.0
Has anyone else seen this and been able to resolve?
This is running behind a corporate proxy which I have no control over, but the HTTP requests for service discovery are working which makes me thing the SSL setup is OK in python requests generally, but there is an issue with websockets.