Getting unknown content type exception for python client

AkashRam
AkashRam edited May 8 in General
Got this error - raise ex.DataException("Unknown Content-Type ({content_type}) with response: ({content})".format(
kiteconnect.exceptions.DataException: Unknown Content-Type (text/html) with response: (b'\r\n502 Bad Gateway\r\n\r\n

502 Bad Gateway

\r\n
cloudflare
\r\n\r\n\r\n') when trying to access the kite.orders() endpoint, was working fine till 2.05 PM.

Any help would be appreciated? Thanks.
  • AkashRam
    The whole stack trace -
    Traceback (most recent call last):
    File "/Users/akashram/PycharmProjects/Zerodha Algo/src/Test.py", line 1065, in
    orders = kite.orders()
    ^^^^^^^^^^^^^
    File "/Users/akashram/PycharmProjects/Zerodha Algo/.venv/lib/python3.12/site-packages/kiteconnect/connect.py", line 416, in orders
    return self._format_response(self._get("orders"))
    ^^^^^^^^^^^^^^^^^^^
    File "/Users/akashram/PycharmProjects/Zerodha Algo/.venv/lib/python3.12/site-packages/kiteconnect/connect.py", line 861, in _get
    return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Users/akashram/PycharmProjects/Zerodha Algo/.venv/lib/python3.12/site-packages/kiteconnect/connect.py", line 943, in _request
    raise ex.DataException("Unknown Content-Type ({content_type}) with response: ({content})".format(
    kiteconnect.exceptions.DataException: Unknown Content-Type (text/html) with response: (b'\r\n502 Bad Gateway\r\n\r\n

    502 Bad Gateway

    \r\n
    cloudflare
    \r\n\r\n\r\n')
  • sujith
    It might be issue with ISP and Cloudflare. Is this local or hosted somewhere? Does it have static IP?
  • AkashRam
    Hi Sujith, thanks for the response. It’s run from local system. Had a doubt if it was an issue between isp and cdn, anything else I can do from my end to make sure the code doesn’t break? I’ve been running this for a few months, facing 502 for the first time. Thanks
  • rakeshr
    Do you get 502 for all API requests? Or only for orders? Was it intermittent or happen continuously?
    anything else I can do from my end to make sure the code doesn’t break?
    If it's intermittent, you can handle it with retry.
  • AkashRam
    Hey Rakesh, thanks for the response, it was intermittent, have handled all data exceptions with retry now, thanks. Any idea why this happened though?
  • sujith
    It could be because of the issue between the ISP and CDN. If it is a recurring issue then it is better to run the program on cloud.
  • AkashRam
    Thanks Sujith, thought that was the issue too. It is intermittent, you can close the thread.
This discussion has been closed.