Hi, during placing orders, I am getting frequent API Connection Forcibly Closed Errors. What’s the problem? Why would the server forcibly close connections? This originates in these lines of your API:
body = upstox_client.PlaceOrderRequest(**params) # PlaceOrderRequest |
response = self.order_api_instance.place_order(body, self.api_version)
2024-09-23 13:39:08 - INFO - ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)), Traceback (most recent call last):
File "D:\Program Files\Python\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "D:\Program Files\Python\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "D:\Program Files\Python\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "D:\Program Files\Python\lib\http\client.py", line 1344, in getresponse
response.begin()
File "D:\Program Files\Python\lib\http\client.py", line 307, in begin
version, status, reason = self._read_status()
File "D:\Program Files\Python\lib\http\client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "D:\Program Files\Python\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "D:\Program Files\Python\lib\ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "D:\Program Files\Python\lib\ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\strategyu\UpstoxAPI.py", line 54, in _place_order_api
response = self.order_api_instance.place_order(body, self.api_version)
File "D:\Program Files\Python\lib\site-packages\upstox_client\api\order_api.py", line 661, in place_order
(data) = self.place_order_with_http_info(body, api_version, **kwargs) # noqa: E501
File "D:\Program Files\Python\lib\site-packages\upstox_client\api\order_api.py", line 732, in place_order_with_http_info
return self.api_client.call_api(
File "D:\Program Files\Python\lib\site-packages\upstox_client\api_client.py", line 316, in call_api
return self.__call_api(resource_path, method,
File "D:\Program Files\Python\lib\site-packages\upstox_client\api_client.py", line 148, in __call_api
response_data = self.request(
File "D:\Program Files\Python\lib\site-packages\upstox_client\api_client.py", line 358, in request
return self.rest_client.POST(url,
File "D:\Program Files\Python\lib\site-packages\upstox_client\rest.py", line 263, in POST
return self.request("POST", url,
File "D:\Program Files\Python\lib\site-packages\upstox_client\rest.py", line 161, in request
r = self.pool_manager.request(
File "D:\Program Files\Python\lib\site-packages\urllib3\request.py", line 78, in request
return self.request_encode_body(
File "D:\Program Files\Python\lib\site-packages\urllib3\request.py", line 170, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "D:\Program Files\Python\lib\site-packages\urllib3\poolmanager.py", line 376, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "D:\Program Files\Python\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "D:\Program Files\Python\lib\site-packages\urllib3\util\retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "D:\Program Files\Python\lib\site-packages\urllib3\packages\six.py", line 769, in reraise
raise value.with_traceback(tb)
File "D:\Program Files\Python\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "D:\Program Files\Python\lib\site-packages\urllib3\connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "D:\Program Files\Python\lib\site-packages\urllib3\connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
File "D:\Program Files\Python\lib\http\client.py", line 1344, in getresponse
response.begin()
File "D:\Program Files\Python\lib\http\client.py", line 307, in begin
version, status, reason = self._read_status()
File "D:\Program Files\Python\lib\http\client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "D:\Program Files\Python\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "D:\Program Files\Python\lib\ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "D:\Program Files\Python\lib\ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))