youngsoul / PyParticleIO

Python ParticleIO cloud API
Other
14 stars 5 forks source link

unhandled ConnectionAbortedError #10

Closed laheym closed 1 year ago

laheym commented 1 year ago

Thanks for sharing your module

I apparently lost connection and the following error was thrown (path to venv was redacted with XXX). A tool that is reading data from the internet should probably handle a disconnect more gently. After the ParticleCloud thread stopped, it stopped sending events to my handler function. Also looks like you're using time.sleep() in ParticleCloud.py but forgot to import time

Traceback (most recent call last):
  File "XXX\lib\site-packages\pyparticleio\ParticleCloud.py", line 311, in _event_loop
    for msg in sse_client:
  File "XXX\lib\site-packages\sseclient.py", line 92, in __next__
    next_chunk = next(self.resp_iterator)
  File "XXX\lib\site-packages\sseclient.py", line 71, in generate
    chunk = self.resp.raw._fp.fp.read1(self.chunk_size)
  File "C:\Program Files\Python37\Lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
  File "C:\Program Files\Python37\Lib\ssl.py", line 1052, in recv_into
    return self.read(nbytes, buffer)
  File "C:\Program Files\Python37\Lib\ssl.py", line 911, in read
    return self._sslobj.read(len, buffer)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
Error in event loop [],[None]
Exception in thread Thread-1:
Traceback (most recent call last):
  File "XXX\lib\site-packages\pyparticleio\ParticleCloud.py", line 311, in _event_loop
    for msg in sse_client:
  File "XXX\lib\site-packages\sseclient.py", line 92, in __next__
    next_chunk = next(self.resp_iterator)
  File "XXX\lib\site-packages\sseclient.py", line 71, in generate
    chunk = self.resp.raw._fp.fp.read1(self.chunk_size)
  File "C:\Program Files\Python37\Lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
  File "C:\Program Files\Python37\Lib\ssl.py", line 1052, in recv_into
    return self.read(nbytes, buffer)
  File "C:\Program Files\Python37\Lib\ssl.py", line 911, in read
    return self._sslobj.read(len, buffer)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python37\Lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python37\Lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "XXX\lib\site-packages\pyparticleio\ParticleCloud.py", line 322, in _event_loop
    time.sleep(60)
NameError: name 'time' is not defined
laheym commented 1 year ago

ah... I see. You are catching ALL exceptions. it's just your exception handling block raises the NameError because you're missing import time

youngsoul commented 1 year ago

Thanks very much for catching this and the PR. I have merged it and released a new version.