raise ex.DataException("Couldn't parse the JSON response received from the server

SwapnilC
I am getting following error intermittently today morning. Is there any issue with the server?

raise ex.DataException("Couldn't parse the JSON response received from the server: {content}".format(
kiteconnect.exceptions.DataException: Couldn't parse the JSON response received from the server: b'

503 Service Unavailable

\nNo server is available to handle this request.\n\n'

I checked the server status on this link - https://www.cloudflarestatus.com/ But it says: "All Systems Operational".

Fetched above link from here: https://zerodha.com/marketintel/bulletin/325623/intermittent-connectivity-issue-on-kite

Anyone facing similar issue?
  • ashokbinra
    i am facing same problem , according to AI ""The error message suggests that the JSON response received from the server could not be parsed, and a JSONDecodeError occurred. Additionally, the traceback shows that the initial error occurred in the _request method of the kiteconnect.connect module.

    However, the second error message indicates that the server returned a 503 Service Unavailable error, which suggests that there might be an issue with the server and not necessarily with the code. This could be a temporary issue, and you may want to try running the code again later to see if the issue has been resolved.

    If the issue persists, you may want to check the documentation for the kiteconnect package to ensure that you are using the correct methods and parameters. Additionally, you can try contacting the support team for the API or the server to see if they can provide any insights into the issue.""
    also
    "" the keys in the dictionary are using single quotes instead of double quotes, which is causing a syntax error when attempting to parse the dictionary as JSON.""
  • bgogri14
    I am getting the same error intermittently, I don't understand if it is a Kite Issue or some code issue. The same piece of code has been working for a long time though.
  • rakeshr
    Are you still facing the issue? If yes, can you paste here the complete request log?
  • rahilbhansali
    I was facing this issue on saturday, sunday and this morning at 8am. Kite suddenly was failing during the historical candle api.

    Was some service down? Has some rate limit changed?
  • nikhilramesh88
    nikhilramesh88 edited March 2023
    still facing this intermittent issue:
    Couldn't parse the JSON response received from the server: b'

    503 Service Unavailable

    \nNo server is available to handle this request.\n\n
  • kamlesh1
    I'm getting same error code. Till yesterday the code was working. Error which I'm getting is:

    kite.ltp(ticker_symbol[i])[ticker_symbol[i]]["last_price"]
    ~\anaconda3\lib\site-packages\kiteconnect\connect.py in ltp(self, *instruments)
    608 ins = instruments[0]
    609
    --> 610 return self._get("market.quote.ltp", params={"i": ins})
    611
    612 def historical_data(self, instrument_token, from_date, to_date, interval, continuous=False, oi=False):

    ~\anaconda3\lib\site-packages\kiteconnect\connect.py in _get(self, route, url_args, params, is_json)
    849 def _get(self, route, url_args=None, params=None, is_json=False):
    850 """Alias for sending a GET request."""
    --> 851 return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)
    852
    853 def _post(self, route, url_args=None, params=None, is_json=False, query_params=None):

    ~\anaconda3\lib\site-packages\kiteconnect\connect.py in _request(self, route, method, url_args, params, is_json, query_params)
    914 data = r.json()
    915 except ValueError:
    --> 916 raise ex.DataException("Couldn't parse the JSON response received from the server: {content}".format(
    917 content=r.content))
    918

    DataException: Couldn't parse the JSON response received from the server: b'

    503 Service Unavailable

    \nNo server is available to handle this request.\n\n'
  • ashi124524
    Same problem even I am getting today 10:24 am
  • linsuresh
    linsuresh edited March 2023
    kiteconnect.exceptions.DataException: Couldn't parse the JSON response received from the server: b'

    503 Service Unavailable

    \nNo server is available to handle this request.\n\n'

    I am also getting this error every now and then since morning. one order got executed and the program exited when trying to execute another other at 9:40

    Here is the log.
    Traceback (most recent call last):
    File "/home/ec2-user/.local/lib/python3.7/site-packages/kiteconnect/connect.py", line 900, in _request
    data = json.loads(r.content.decode("utf8"))
    File "/usr/lib64/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
    File "/usr/lib64/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    File "/usr/lib64/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  • ashi124524
    It's risky to run algo with this error message. What if the algo stops in between while trade is still running in zerodha?
  • AyushGarg
    I am also facing the same issue today.
    DataException: Couldn't parse the JSON response received from the server: b'

    503 Service Unavailable

    \nNo server is available to handle this request.\n\n'
  • madanus
    Have raised the same issue in the support portal - #20230318718552 – Kite API frequent errors
    Zerodha support team is in denial - they need more instances to raise the priority on this issue.

    pl use the above ticket no as a reference and create your own ticket to raise the priority on this one.

    Man, this is killing me today.
  • madanus
    I hve been facing this issue since saturday and the frequency of this error is increasing.
  • madanus
    I think this is a load balancer issue - or the request load has increased and they have to provision more servers to handle the extra load.
  • kkm1982
    Facing the same issue:
    Exception has occurred: DataException
    Couldn't parse the JSON response received from the server: b'

    503 Service Unavailable

    \nNo server is available to handle this request.\n\n'
    StopIteration: 0

    During handling of the above exception, another exception occurred:

    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

    During handling of the above exception, another exception occurred:

    File "C:\Work\PythonProjects\stockIVs.py", line 185, in
    fut_quote = kite.quote(tokenfut)[tokenfut]
    kiteconnect.exceptions.DataException: Couldn't parse the JSON response received from the server: b'
  • ashi124524
    And the algo stops working after a certain number of these error messages.
  • ashi124524
    while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
  • ashi124524
    it's risky people. don't run algo today.
  • sujith
    This should be fixed now. Few of the users were affected by this.
  • madanus
    Sujith - are you from Zerodha? Are you saying the issue is fixed now? Can we know the RCA pl.
  • sujith
    sujith edited March 2023
    There was an internal DNS issue which caused this error for about 5% of our users requests.
  • ratnambaba
    Sujith - is that issue fixed or not yet?
  • sujith
    sujith edited March 2023
    It is fixed now as mentioned above.
  • ashi124524
    Yes it now resolved. But the day is over for the algo.
  • madanus
    @sujith Happened again -different error this time:

    ◐2023-03-20 13:19:00.703972
    Traceback (most recent call last):
    File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
    File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
    File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
    File "/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py", line 770, in reraise
    raise value
    File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
    File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 389, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
    File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 340, in _raise_timeout
    raise ReadTimeoutError(
    urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/usr/local/lib/python3.9/site-packages/kiteconnect/connect.py", line 606, in ltp
    return self._get("market.quote.ltp", params={"i": ins})
    File "/usr/local/lib/python3.9/site-packages/kiteconnect/connect.py", line 842, in _get
    return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)
    File "/usr/local/lib/python3.9/site-packages/kiteconnect/connect.py", line 897, in _request
    raise e
    File "/usr/local/lib/python3.9/site-packages/kiteconnect/connect.py", line 885, in _request
    r = self.reqsession.request(method,
    File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
    File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
    File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
    File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 578, in send
    raise ReadTimeout(e, request=request)
    requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)
    Exception:HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)
    Exception:HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=
  • sujith
    Is this a local setup or cloud?
  • rahilbhansali
    @sujith - It seems to be working for me now too. Thanks for the fix.

    Can this be handled a little more promptly next time / alert-driven? This has downstream impacts for all of us involved.
  • madanus
    @sujith am running this on my mac - is that what you wanted to know?
  • madanus
    @rahilbhansali +1 on that Rahil - @sujith can Zerodha provide us with a real time view of the health of the APIs - we could atleast consolidate our positions and hold our algo/trades if we know that there are service isses wrt the API.

    5% might be a small percentage, but it is not complete failure for 5% of customers - it is 5% of times (or less) for any customer. But since the error is intermittent - we cant take a call on whether to run the algo or not. Hope you understand.
  • SwapnilC
    SwapnilC edited March 2023
    @sujith, I had checked the server status on this link - https://www.cloudflarestatus.com/ But it said: "All Systems Operational".

    Fetched above link from here: https://zerodha.com/marketintel/bulletin/325623/intermittent-connectivity-issue-on-kite

    This was misleading and we couldn't understand if it was the problem with server or with our scripts. The former possibility was high as the scripts worked fine until server started behaving erratically.

    Is there any way to check Server Health? It would help us all i.e. those 5% affected, to take appropriate measure until such issue is resolved.

    We understand that such issues may not be fixed as soon as they are reported, especially over the weekend and on Monday mornings before business hours. But I am sure you are aware about the extent of adverse financial implications such issues have.
  • SNRaj
    @sujith - I am getting the same error today as well. (kiteconnect.exceptions.DataException: Couldn't parse the JSON response received from the server: b'). Please let me know when this issue will be addressed permanently. This is producing unwanted losses.
  • SNRaj
    Is this issue resolved ?
Sign In or Register to comment.