zerodha / pykiteconnect

The official Python client library for the Kite Connect trading APIs
MIT License
978 stars 467 forks source link

"Unknown Content-Type" data exception for quotes: consistently reproducible #104

Closed dhwanit-webrmedia closed 3 years ago

dhwanit-webrmedia commented 3 years ago

Fetching a specific set of 500 quotes consistently fails with the following exception:

  File "/Users/dhwanit/.pyenv/versions/3.8.6/lib/python3.8/site-packages/kiteconnect/connect.py", line 570, in quote
    data = self._get("market.quote", params={"i": ins})
  File "/Users/dhwanit/.pyenv/versions/3.8.6/lib/python3.8/site-packages/kiteconnect/connect.py", line 822, in _get
    return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)
  File "/Users/dhwanit/.pyenv/versions/3.8.6/lib/python3.8/site-packages/kiteconnect/connect.py", line 900, 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'<html><body><h1>400 Bad request</h1>\nYour browser sent an invalid request.\n</body></html>\n')

The script that fails is available in this gist: https://gist.github.com/dhwanit-webrmedia/d7ea00183440d748c4de05c84a84eaae

I just run it as a django shell script (since my kite session access token is retrieved from the DB)...

python manage.py shell < bad_request.py

...but setting up the kite object in the gist script with the correct access token should allow you to reproduce this issue consistently.

I'm using Python 3.8.6 with KiteConnect 3.9.0.

Please let me know if anything else is needed, I'd be happy to assist in any way I can!

vividvilla commented 3 years ago

Seems like the request is malformed, most probably its exceeding the max URL length. Try reducing the number of instrument tokens you send to quote() call.