'utf-8' codec can't decode byte 0x80 in position 22: invalid start byte
When testing websocketapi example using python for market_price, I have encountered an error 'utf-8' codec can't decode byte 0x80 in position 22: invalid start byte.
I have tested the same using the wsapi application tool and I was able to retrieve the market price using my hostname and port 15000 successfully. However, I end up getting an error "'utf-8' codec can't decode byte 0x80 in position 22: invalid start byte" when using python.
python market_price.py --hostname "myhostname" --port "15000"
'utf-8' codec can't decode byte 0x80 in position 22: invalid start byte
WebSocket Closed
Could you please assist?
Best Answer
-
Hi @nitin.jagwani ,
We detected same issue when we use websocket-client lib.
(see https://websocket-client.readthedocs.io/en/latest/faq.html#i-get-the-error-utf8-codec-can-t-decode-byte-0x81-in-position-0)
It can be fixed by overriding websocket.read_headers function to replace 'utf-8' decoding with 'ISO-8859-1' decoding.import websocket
def my_read_headers(sock):
status = None
status_message = None
headers = {}
trace("--- response header ---")
while True:
line = recv_line(sock)
trace(line)
line = line.decode('ISO-8859-1').strip()
# line = line.decode('utf-8')
line = line.strip()
if not line:
break
trace(line)
if not status:
status_info = line.split(" ", 2)
status = int(status_info[1])
if len(status_info) > 2:
status_message = status_info[2]
else:
kv = line.split(":", 1)
if len(kv) == 2:
key, value = kv
if key.lower() == "set-cookie" and headers.get("set-cookie"):
headers["set-cookie"] = headers.get("set-cookie") + "; " + value.strip()
else:
headers[key.lower()] = value.strip()
else:
raise WebSocketException("Invalid header")
trace("-----------------------")
return status, headers, status_message
websocket.read_headers = my_read_headers2
Answers
-
Hi @nitin.jagwani
Please advise which RIC code(s) you are subscribing to when you see the above error.
0 -
Hi
This issue still persists, and I just encountered it when streaming through a platform-session, where the utf-8 decoding caused trouble with my particular application-id.
I realize that managing the WebSocket library is out of scope on this forum, however, I would suggest that the RD library incorporate a temporary handling of this error, so that end-users don't have to bother with it.
Details on my specific case.
-----------------------------------------------------------------------------------------------------------------------------------0
Categories
- All Categories
- 6 AHS
- 39 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛