Code stuck at kite.order()

ksh
Hi. I have a mechanism to poll kite orders every 15 minutes using kite.orders().
However, i am noticing since some time, the polling code gets stuck at this call kite.orders
Here is the traceback obtained on ^C: Ideally there should have been a timeout exception from api. Plz tell me a way to handle this.


^CTraceback (most recent call last):
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/urllib3/connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/urllib3/connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File ".../anaconda3/envs/kite/lib/python3.8/http/client.py", line 1348, in getresponse
response.begin()
File ".../anaconda3/envs/kite/lib/python3.8/http/client.py", line 316, in begin
version, status, reason = self._read_status()
File ".../anaconda3/envs/kite/lib/python3.8/http/client.py", line 277, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File ".../anaconda3/envs/kite/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File ".../anaconda3/envs/kite/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File ".../anaconda3/envs/kite/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/urllib3/util/retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/urllib3/packages/six.py", line 770, in reraise
raise value
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/urllib3/connectionpool.py", line 451, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File ".../anaconda3/envs/kite/lib/python3.8/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 "kite_ticker.py", line 256, in main_thread
monitor_threads(kite)
File "kite_ticker.py", line 223, in monitor_threads
poll_kite_dashboard(kite, ... g_fileLogger)
File ".../kite_script/kite_polling.py", line 73, in poll_kite_dashboard
orders_stat_dict = parse_dashboard_orders(kite, ... fileLogger)
File ".../kite_script/kite_polling.py", line 22, in parse_dashboard_orders
<b class="Bold"><b class="Bold">all_orders = kite.orders() # list of orders</b></b>
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/kiteconnect/connect.py", line 415, in orders
return self._format_response(self._get("orders"))
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/kiteconnect/connect.py", line 851, in _get
return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/kiteconnect/connect.py", line 906, in _request
raise e
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/kiteconnect/connect.py", line 894, in _request
r = self.reqsession.request(method,
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File ".../anaconda3/envs/kite/lib/python3.8/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File ".../anaconda3/envs/kite/lib/python3.8/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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "kite_ticker.py", line 312, in <module>
main_thread(kite, ...)
File "kite_ticker.py", line 259, in main_thread
terminate_all_threads(g_thread_pool_exec, g_thread_kill_sig, kws_l)
File ".../anaconda3/envs/kite/lib/python3.8/concurrent/futures/_base.py", line 644, in __exit__
self.shutdown(wait=True)
File ".../anaconda3/envs/kite/lib/python3.8/concurrent/futures/thread.py", line 236, in shutdown
t.join()
File ".../anaconda3/envs/kite/lib/python3.8/threading.py", line 1011, in join
self._wait_for_tstate_lock()
File ".../anaconda3/envs/kite/lib/python3.8/threading.py", line 1027, in _wait_for_tstate_lock
elif lock.acquire(block, timeout):
KeyboardInterrupt

  • rakeshr
    requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)
    You need to handle timeout here.
  • ksh
    This exception is raised by default by requests . correct ? If the exception was raised, my code should have crashed as i am not handling it .
Sign In or Register to comment.