Unknown Content-Type error

srinidhihebbar
srinidhihebbar edited March 2023 in Python client
"(application/xml) with response: (b'<?xml version="1.0" encoding="UTF-8"?>\nInvalidArgumentUnsupported Authorization TypeAuthorizationtoken 0l7xeons4dlvxh37:4Q3BmqwibQ93WsQd4KfIilBhnSi7gz0B6F9Q8DG23SJ6AX1WrkdN9jZ5y0rv96Lj+ftlQDfCEhH9u01H6Bowv8origGySup6/kP71gdnAZdOYPsVocZbmApc+ZQ=')"


What is this error, it was thrown after 5 retries as well.
Tagged:
  • sujith
    Can you let us know for which API call you are getting this?
  • srinidhihebbar
    I have told in the other thread as well, it is thrown whatever the first API call is, the current screenshot is for

    Fno_Instruments=kite.instruments('NFO')).sort_values(by='expiry')
  • tonystark
    We have applied a potential fix to this issue last week. Let us know if this is occurring again.
  • srinidhihebbar
    Did not occur post that. But the timed out screwed up a lot of trades for me today.
  • rakeshr
    But the timed out screwed up a lot of trades for me today
    Can you paste here detailed debug log along with the requested API end-point here? Are time-out specific only for an API call or for all kiteconnect API end-points?
  • srinidhihebbar
    I am not saving the logs , It occurred for different calls so I am not really sure if it is for a specific call.
  • srinidhihebbar
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "GET /user/margins HTTP/1.1" 200 None
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "GET /instruments/NFO HTTP/1.1" 200 621995
    Traceback (most recent call last):

    File ~\anaconda3\lib\site-packages\urllib3\connectionpool.py:449 in _make_request
    six.raise_from(e, None)

    File :3 in raise_from

    File ~\anaconda3\lib\site-packages\urllib3\connectionpool.py:444 in _make_request
    httplib_response = conn.getresponse()

    File ~\anaconda3\lib\http\client.py:1377 in getresponse
    response.begin()

    File ~\anaconda3\lib\http\client.py:320 in begin
    version, status, reason = self._read_status()

    File ~\anaconda3\lib\http\client.py:281 in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")

    File ~\anaconda3\lib\socket.py:704 in readinto
    return self._sock.recv_into(b)

    File ~\anaconda3\lib\ssl.py:1241 in recv_into
    return self.read(nbytes, buffer)

    File ~\anaconda3\lib\ssl.py:1099 in read
    return self._sslobj.read(len, buffer)

    timeout: The read operation timed out


    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):

    File ~\anaconda3\lib\site-packages\requests\adapters.py:440 in send
    resp = conn.urlopen(

    File ~\anaconda3\lib\site-packages\urllib3\connectionpool.py:785 in urlopen
    retries = retries.increment(

    File ~\anaconda3\lib\site-packages\urllib3\util\retry.py:550 in increment
    raise six.reraise(type(error), error, _stacktrace)

    File ~\anaconda3\lib\site-packages\urllib3\packages\six.py:770 in reraise
    raise value

    File ~\anaconda3\lib\site-packages\urllib3\connectionpool.py:703 in urlopen
    httplib_response = self._make_request(

    File ~\anaconda3\lib\site-packages\urllib3\connectionpool.py:451 in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)

    File ~\anaconda3\lib\site-packages\urllib3\connectionpool.py:340 in _raise_timeout
    raise ReadTimeoutError(

    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 ~\OneDrive\Desktop\untitled2.py:137 in
    available_margin=kite.margins()['equity']['net']

    File ~\anaconda3\lib\site-packages\kiteconnect\connect.py:328 in margins
    return self._get("user.margins")

    File ~\anaconda3\lib\site-packages\kiteconnect\connect.py:851 in _get
    return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)

    File ~\anaconda3\lib\site-packages\kiteconnect\connect.py:906 in _request
    raise e

    File ~\anaconda3\lib\site-packages\kiteconnect\connect.py:894 in _request
    r = self.reqsession.request(method,

    File ~\anaconda3\lib\site-packages\requests\sessions.py:529 in request
    resp = self.send(prep, **send_kwargs)

    File ~\anaconda3\lib\site-packages\requests\sessions.py:645 in send
    r = adapter.send(request, **kwargs)

    File ~\anaconda3\lib\site-packages\requests\adapters.py:532 in send
    raise ReadTimeout(e, request=request)

    ReadTimeout: HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)


    the request was for instruments api
  • srinidhihebbar
    Happened Again , it happened for margin API call
  • srinidhihebbar
    Whenever the same API call is being sent in a loop this error is thrown .
  • srinidhihebbar
    File "C:\Users\ramakrishna\Desktop\minandstra.py", line 655, in
    straddle()

    File "C:\Users\ramakrishna\Desktop\minandstra.py", line 517, in straddle
    get_single_side_margin(instrument_buy=put_buy_strike, instrument_sell=put_strike_sell, qty=int(put_total_qty))

    File "C:\Users\ramakrishna\Desktop\minandstra.py", line 262, in get_single_side_margin
    basket_order_margin_single=kite.basket_order_margins([{

    File "C:\ProgramData\Anaconda3\lib\site-packages\kiteconnect\connect.py", line 780, in basket_order_margins
    return self._post("order.margins.basket",

    File "C:\ProgramData\Anaconda3\lib\site-packages\kiteconnect\connect.py", line 846, in _post
    return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json, query_params=query_params)

    File "C:\ProgramData\Anaconda3\lib\site-packages\kiteconnect\connect.py", line 924, in _request
    raise ex.DataException("Unknown Content-Type ({content_type}) with response: ({content})".format(

    DataException: Unknown Content-Type (text/html) with response: (b"

    504 Gateway Time-out

    \nThe server didn't respond in time.\n\n")
  • rakeshr
    GET /instruments/NFO HTTP/1.1
    Whenever the same API call is being sent in a loop this error is thrown .
    It's not recommended to download the instrument file for each request, but store it once at the start of the day locally and consume the same for further requests. The warning section in the documentation explains the same.
  • srinidhihebbar
    This happened for basket margin Rakesh!!
    Not for Instruments, I am sorry I wrote it as Seperate comments.

    srinidhihebbar
    srinidhihebbar 9:52AM Flag
    Happened Again , it happened for margin API call
  • srinidhihebbar
    There is no way to get basket margin without looping it
  • rakeshr
    Whenever the same API call is being sent in a loop this error is thrown .
    504 Gateway Time-out
    Are you making API calls exceeding the rate limits, in the loop? Add some seconds delay, for the next request in the loop.
Sign In or Register to comment.