Unauthorized 401 from Websocket connection

HI

I am getting Unauthorized 401 error while making Websocket connection to Upstox backend. However the call to get Historic Data is working fine. I am only facing issue with Websocket connection.
Please check.

upstox_client.rest.ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({‘Date’: ‘Thu, 30 May 2024 07:09:49 GMT’, ‘Content-Type’: ‘application/json’, ‘Transfer-Encoding’: ‘chunked’, ‘Connection’: ‘keep-alive’, ‘X-Content-Type-Options’: ‘nosniff’, ‘X-XSS-Protection’: ‘1; mode=block’, ‘Pragma’: ‘no-cache’, ‘Strict-Transport-Security’: ‘max-age=0; includeSubDomains’, ‘X-Frame-Options’: ‘DENY’, ‘Cache-Control’: ‘must-revalidate,no-cache,no-store’, ‘Vary’: ‘Origin, Access-Control-Request-Method, Access-Control-Request-Headers’, ‘message’: ‘request failed’, ‘CF-Cache-Status’: ‘DYNAMIC’, ‘Set-Cookie’: ‘__cf_bm=T1rXTv67.AY8oNeu6s_ZU4wFS.wmO05dL84Ff_AoIkQ-1717052989-1.0.1.1-UgT65MOss9I_7F7VrDNcErHkHbxcj_QG8NlIeVQXYo9Rz1pfBE7aYM1aaof3Ay_c; path=/; expires=Thu, 30-May-24 07:39:49 GMT; domain=.upstox.com; HttpOnly; Secure; SameSite=None, _cfuvid=y8e3tpRoAWtJC8xSnFFNdnqfi60PYpFfBhYpwKeeU4s-1717052989075-0.0.1.1-604800000; path=/; domain=.upstox.com; HttpOnly; Secure; SameSite=None’, ‘Server’: ‘cloudflare’, ‘CF-RAY’: ‘88bce69d89523fe4-BOM’})
HTTP response body: b’{“status”:“error”,“errors”:[{“errorCode”:“UDAPI100050”,“message”:“Invalid token used to access API”,“propertyPath”:null,“invalidValue”:null,“error_code”:“UDAPI100050”,“property_path”:null,“invalid_value”:null}]}’

Our Historical API is designed as an open API, which means it does not require authorization. As a result, even if you provide an invalid access token in the header, the API will still return a successful response.

For detailed instructions on the authentication procedure, please refer to our API Documentation | Authentication. Additionally, please note that the access token is valid for one day and expires at 3:30 AM.

2 Likes

I tried but getting UDAPI100060 error.

INFO:main:Token response: {“status”:“error”,“errors”:[{“errorCode”:“UDAPI100060”,“message”:“Resource not Found.”,“propertyPath”:null,“invalidValue”:null,“error_code”:“UDAPI100060”,“property_path”:null,“invalid_value”:null}]}
ERROR:main:Failed to obtain access token: {“status”:“error”,“errors”:[{“errorCode”:“UDAPI100060”,“message”:“Resource not Found.”,“propertyPath”:null,“invalidValue”:null,“error_code”:“UDAPI100060”,“property_path”:null,“invalid_value”:null}]}
INFO:werkzeug:127.0.0.1 - - [02/Jun/2024 13:24:31] “GET /callback?code=DWpGqA HTTP/1.1” 400 -

Please generate a new access token and try to fetch data from websocket. If still the problem persists and please share the source code you are using along with our upstox user id for further investigation.

Thanks,