I was able to run api properly, but for last 3 days its not working

Traceback (most recent call last):
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py”, line 789, in urlopen
response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py”, line 490, in _make_request
raise new_e
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connection.py”, line 730, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connection.py”, line 909, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
^^^^^^^^^^^^^^^^
File "C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\ssl
.py", line 469, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\ssl
.py", line 513, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\ssl.py”, line 517, in wrap_socket
return self.sslsocket_class._create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\ssl.py”, line 1075, in _create
self.do_handshake()
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\ssl.py”, line 1346, in do_handshake
self._sslobj.do_handshake()
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 “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\adapters.py”, line 667, in send
resp = conn.urlopen(
^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py”, line 843, in urlopen
retries = retries.increment(
^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\retry.py”, line 474, in increment
raise reraise(type(error), error, _stacktrace)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\util.py”, line 38, in reraise
raise value.with_traceback(tb)
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py”, line 789, in urlopen
response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py”, line 490, in _make_request
raise new_e
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py”, line 466, in _make_request
self._validate_conn(conn)
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py”, line 1095, in _validate_conn
conn.connect()
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connection.py”, line 730, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connection.py”, line 909, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
^^^^^^^^^^^^^^^^
File "C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\ssl
.py", line 469, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\ssl
.py", line 513, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\ssl.py”, line 517, in wrap_socket
return self.sslsocket_class._create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\ssl.py”, line 1075, in _create
self.do_handshake()
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\ssl.py”, line 1346, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: (‘Connection aborted.’, ConnectionResetError(10054, ‘An existing connection was forcibly closed by the remote host’, None, 10054, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “d:\2\stockmarket\Algo Trading\Python code\UPSTOX_API\UPSTOX_CODE\UPSTOX_CODE\succcess_files\Checking step by step\Check_combined_data_every_5 min\Websocket_with other functions - Copy_for testing step by step.py”, line 564, in
resampled_data = combine_data()
^^^^^^^^^^^^^^
File “d:\2\stockmarket\Algo Trading\Python code\UPSTOX_API\UPSTOX_CODE\UPSTOX_CODE\succcess_files\Checking step by step\Check_combined_data_every_5 min\Websocket_with other functions - Copy_for testing step by step.py”, line 241, in combine_data
intraday_data = fetch_intraday_data()
^^^^^^^^^^^^^^^^^^^^^
File “d:\2\stockmarket\Algo Trading\Python code\UPSTOX_API\UPSTOX_CODE\UPSTOX_CODE\succcess_files\Checking step by step\Check_combined_data_every_5 min\Websocket_with other functions - Copy_for testing step by step.py”, line 171, in fetch_intraday_data
response = rq.request(“GET”, url, headers=headers).json()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\api.py”, line 59, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\sessions.py”, line 589, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\adapters.py”, line 682, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: (‘Connection aborted.’, ConnectionResetError(10054, ‘An existing connection was forcibly closed by the remote host’, None, 10054, None))
Exception in thread Thread-1 (run_websocket):
Exception in thread Thread-13 (run_websocket):
Traceback (most recent call last):
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py”, line 494, in finish_recv
Traceback (most recent call last):
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py”, line 494, in finish_recv
return ov.getresult()
return ov.getresult()
^^^^^^^^^^^^^^
OSError: [WinError 64] The specified network name is no longer available
^^^^^^^^^^^^^^

During handling of the above exception, another exception occurred:
OSError: [WinError 64] The specified network name is no longer available

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 953, in transfer_data
Traceback (most recent call last):
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 953, in transfer_data
message = await self.read_message()
message = await self.read_message()
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1023, in read_message
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1023, in read_message
frame = await self.read_data_frame(max_size=self.max_size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1098, in read_data_frame
frame = await self.read_data_frame(max_size=self.max_size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1098, in read_data_frame
frame = await self.read_frame(max_size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1155, in read_frame
frame = await self.read_frame(max_size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
frame = await Frame.read(
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1155, in read_frame
^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\framing.py”, line 70, in read
frame = await Frame.read(
^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\framing.py”, line 70, in read
data = await reader(2)
data = await reader(2)
^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\streams.py”, line 729, in readexactly
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\streams.py”, line 729, in readexactly
await self._wait_for_data(‘readexactly’)
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\streams.py”, line 522, in _wait_for_data
await self._wait_for_data(‘readexactly’)
await self._waiter
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py”, line 286, in _loop_reading
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\streams.py”, line 522, in _wait_for_data
await self._waiter
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py”, line 286, in _loop_reading
length = fut.result()
^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py”, line 846, in _poll
length = fut.result()
^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py”, line 846, in _poll
value = callback(transferred, key, ov)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py”, line 498, in finish_recv
value = callback(transferred, key, ov)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
raise ConnectionResetError(*exc.args)
ConnectionResetError: [WinError 64] The specified network name is no longer available

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\threading.py”, line 1038, in _bootstrap_inner
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py”, line 498, in finish_recv
raise ConnectionResetError(*exc.args)
ConnectionResetError: [WinError 64] The specified network name is no longer available

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\threading.py”, line 1038, in _bootstrap_inner
self.run()
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\threading.py”, line 975, in run
self._target(*self._args, **self._kwargs)
self.run()
File “d:\2\stockmarket\Algo Trading\Python code\UPSTOX_API\UPSTOX_CODE\UPSTOX_CODE\succcess_files\Checking step by step\Check_combined_data_every_5 min\Websocket_with other functions - Copy_for testing step by step.py”, line 551, in run_websocket
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\threading.py”, line 975, in run
loop.run_until_complete(fetch_market_data())
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 653, in run_until_complete
self._target(*self._args, **self._kwargs)
File “d:\2\stockmarket\Algo Trading\Python code\UPSTOX_API\UPSTOX_CODE\UPSTOX_CODE\succcess_files\Checking step by step\Check_combined_data_every_5 min\Websocket_with other functions - Copy_for testing step by step.py”, line 537, in run_websocket
loop.run_until_complete(fetch_market_data())
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File “d:\2\stockmarket\Algo Trading\Python code\UPSTOX_API\UPSTOX_CODE\UPSTOX_CODE\succcess_files\Checking step by step\Check_combined_data_every_5 min\Websocket_with other functions - Copy_for testing step by step.py”, line 102, in fetch_market_data
message = await websocket.recv()
^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 562, in recv
return future.result()
^^^^^^^^^^^^^^^
File “d:\2\stockmarket\Algo Trading\Python code\UPSTOX_API\UPSTOX_CODE\UPSTOX_CODE\succcess_files\Checking step by step\Check_combined_data_every_5 min\Websocket_with other functions - Copy_for testing step by step.py”, line 102, in fetch_market_data
message = await websocket.recv()
^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 562, in recv
await self.ensure_open()
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 929, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent
await self.ensure_open()
File “C:\Users\Albin\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 929, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent

Hi @Albin_Varghese,

Could you please provide us with additional details to assist in investigating the issue? Specifically:

  • The time when you encountered the issue.
  • The API or WebSocket you were using.
  • The specific error message you received.

Thank you for your cooperation.

[Code I am using UPSTOX Api ]
(Copy - Google Drive)

I run the code at 9 PM. It ran perfectly until 9:12 PM, then an error occurred.
The same thing happened during market hours; it ran for a while, then an error appeared.
I’ve attached a text file that shows the error. (This is happening even with a good network connection.)

The same code was running the entire trading day without any issues earlier. The errors started occurring from the last month.