Remote end closed connection without response. Happened multiple times. Highlighted in BOLD.

mkrathi
ERROR:root:Exception occurred in BankNiftySpot function at 2023-06-05 14:44:01
Traceback (most recent call last):
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\DDrive\Python\lib\http\client.py", line 1374, in getresponse
response.begin()
File "C:\DDrive\Python\lib\http\client.py", line 318, in begin
version, status, reason = self._read_status()
File "C:\DDrive\Python\lib\http\client.py", line 287, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\DDrive\Python\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "C:\DDrive\Python\lib\site-packages\urllib3\util\retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\DDrive\Python\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\DDrive\Python\lib\http\client.py", line 1374, in getresponse
response.begin()
File "C:\DDrive\Python\lib\http\client.py", line 318, in begin
version, status, reason = self._read_status()
File "C:\DDrive\Python\lib\http\client.py", line 287, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\DDrive\OneDrive\StockTrading\Algo\MyAlgoFunctions.py", line 751, in BankNiftySpot
quote = kite.quote([260105])
File "C:\DDrive\Python\lib\site-packages\kiteconnect\connect.py", line 581, in quote
data = self._get("market.quote", params={"i": ins})
File "C:\DDrive\Python\lib\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 "C:\DDrive\Python\lib\site-packages\kiteconnect\connect.py", line 906, in _request
raise e
File "C:\DDrive\Python\lib\site-packages\kiteconnect\connect.py", line 894, in _request
r = self.reqsession.request(method,
File "C:\DDrive\Python\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\DDrive\Python\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\DDrive\Python\lib\site-packages\requests\adapters.py", line 547, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
ERROR:root:Exception occurred in BankNiftySpot function at 2023-06-06 14:30:32
Traceback (most recent call last):
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\DDrive\Python\lib\http\client.py", line 1374, in getresponse
response.begin()
File "C:\DDrive\Python\lib\http\client.py", line 318, in begin
version, status, reason = self._read_status()
File "C:\DDrive\Python\lib\http\client.py", line 287, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\DDrive\Python\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "C:\DDrive\Python\lib\site-packages\urllib3\util\retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\DDrive\Python\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\DDrive\Python\lib\http\client.py", line 1374, in getresponse
response.begin()
File "C:\DDrive\Python\lib\http\client.py", line 318, in begin
version, status, reason = self._read_status()
File "C:\DDrive\Python\lib\http\client.py", line 287, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\mahendr\OneDrive\StockTrading\Algo\MyAlgoFunctions.py", line 751, in BankNiftySpot
quote = kite.quote([260105])
File "C:\DDrive\Python\lib\site-packages\kiteconnect\connect.py", line 581, in quote
data = self._get("market.quote", params={"i": ins})
File "C:\DDrive\Python\lib\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 "C:\DDrive\Python\lib\site-packages\kiteconnect\connect.py", line 906, in _request
raise e
File "C:\DDrive\Python\lib\site-packages\kiteconnect\connect.py", line 894, in _request
r = self.reqsession.request(method,
File "C:\DDrive\Python\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\DDrive\Python\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\DDrive\Python\lib\site-packages\requests\adapters.py", line 547, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
ERROR:root:Exception occurred in BankNiftySpot function at 2023-06-06 15:55:37
Traceback (most recent call last):
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "", line 3, in raise_from
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "C:\DDrive\Python\lib\http\client.py", line 1374, in getresponse
response.begin()
File "C:\DDrive\Python\lib\http\client.py", line 318, in begin
version, status, reason = self._read_status()
File "C:\DDrive\Python\lib\http\client.py", line 279, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\DDrive\Python\lib\socket.py", line 705, in readinto
return self._sock.recv_into(b)
File "C:\DDrive\Python\lib\ssl.py", line 1274, in recv_into
return self.read(nbytes, buffer)
File "C:\DDrive\Python\lib\ssl.py", line 1130, in read
return self._sslobj.read(len, buffer)
TimeoutError: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\DDrive\Python\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "C:\DDrive\Python\lib\site-packages\urllib3\util\retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\DDrive\Python\lib\site-packages\urllib3\packages\six.py", line 770, in reraise
raise value
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\DDrive\Python\lib\site-packages\urllib3\connectionpool.py", line 451, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "C:\DDrive\Python\lib\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 "c:\DDrive\OneDrive\StockTrading\Algo\MyAlgoFunctions.py", line 751, in BankNiftySpot
quote = kite.quote([260105])
File "C:\DDrive\Python\lib\site-packages\kiteconnect\connect.py", line 581, in quote
data = self._get("market.quote", params={"i": ins})
File "C:\DDrive\Python\lib\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 "C:\DDrive\Python\lib\site-packages\kiteconnect\connect.py", line 906, in _request
raise e
File "C:\DDrive\Python\lib\site-packages\kiteconnect\connect.py", line 894, in _request
r = self.reqsession.request(method,
File "C:\DDrive\Python\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\DDrive\Python\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\DDrive\Python\lib\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)
  • rakeshr
    ERROR:root:Exception occurred in BankNiftySpot function at 2023-06-06 14:30:32
    This is the internal exception message, which may have been generated while handling KiteConnect exceptions. To identify the source of this message, you will need to review your code base.
    requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.kite.trade', port=443): Read timed out. (read timeout=7)
    It appears to be a time-out error from the APIs. Could you please specify the API call causing the time-out and whether you are polling this endpoint?
  • mkrathi
    Hi Rakesh, below is piece of code. I am calling kite.quote with bank nifty instrument token

    Error message I have written is to capture all my exceptions. I dont see any issue with my end. kite.quote is randomly failing once in while
    -----------------------------------------------------------------------
    def BankNiftySpot(kite):
    old_value=prices.mkt_price

    counter=0
    try:
    # Bank Nifty: 260105 (as of September 2021) from NSE
    quote = kite.quote([260105])
    banknifty = int(quote[str(260105)]['last_price'])
    except Exception as e:
    # Log the error message for future
    current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    error_message = f"Exception occurred in BankNiftySpot function at {current_time}"
    logging.exception(error_message)
    # End of error logging
    -----------------------------------------------------------------------
  • rakeshr
    kite.quote is randomly failing once in while
    Might be network related. There are very few time-outs in kiteconnect app logs overall. You need to handle these time-outs with re-try.
  • mkrathi
    You can close this thread. I have switched to ticks instead of quotes. Websockets are more reliable. Thanks for your support

This discussion has been closed.