tchellomello / python-amcrest

A Python 2.7/3.x module for Amcrest and Dahua Cameras using the SDK HTTP API.
GNU General Public License v2.0
213 stars 76 forks source link

event_actions() causes AttributeError #215

Open maxirus opened 2 years ago

maxirus commented 2 years ago

I am connecting to an Amcrest AD410 Doorbell and utilizing the event_actions() method and after about 100s, I receive the Error: AttributeError: 'NoneType' object has no attribute 'read'.

More specifically, I am calling: camera.event_actions("All", retries=5, timeout_cmd=(10.00, 3600)) and with DEBUG log level, I get the follow:

2022-04-30 00:42:29,922 - urllib3.connectionpool [DEBUG] Starting new HTTP connection (1): 192.168.10.20:80
2022-04-30 00:42:29,970 - urllib3.connectionpool [DEBUG] http://192.168.10.20:80 "GET /cgi-bin/eventManager.cgi?action=attach&codes=%5BAll%5D HTTP/1.1" 401 0
2022-04-30 00:44:12,784 - urllib3.connectionpool [DEBUG] http://192.168.10.20:80 "GET /cgi-bin/eventManager.cgi?action=attach&codes=%5BAll%5D HTTP/1.1" 200 None
2022-04-30 00:44:12,785 - amcrest.http [DEBUG] <Doorbell-D66A> Query 9 worked. Exit code: <200>
2022-04-30 00:44:12,786 - amcrest.event [DEBUG] <Doorbell-D66A> event info: '\r\nCode=VideoMotionInfo;action=State;index=0'
  File "/usr/local/lib/python3.10/site-packages/amcrest/event.py", line 361, in event_actions
    for event_info in self.event_stream(
  File "/usr/local/lib/python3.10/site-packages/amcrest/event.py", line 312, in event_stream
    for line in _event_lines(ret.iter_content(decode_unicode=True)):
  File "/usr/local/lib/python3.10/site-packages/amcrest/event.py", line 39, in _event_lines
    for char in ret:
  File "/usr/local/lib/python3.10/site-packages/requests/utils.py", line 549, in stream_decode_response_unicode
    for chunk in iterator:
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 760, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/usr/local/lib/python3.10/site-packages/urllib3/response.py", line 575, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "/usr/local/lib/python3.10/site-packages/urllib3/response.py", line 770, in read_chunked
    chunk = self._handle_chunk(amt)
  File "/usr/local/lib/python3.10/site-packages/urllib3/response.py", line 714, in _handle_chunk
    value = self._fp._safe_read(amt)
  File "/usr/local/lib/python3.10/http/client.py", line 630, in _safe_read
    data = self.fp.read(amt)
AttributeError: 'NoneType' object has no attribute 'read'

What's also odd that I first get a 401 response before eventually getting a 200. Not sure if this is affecting things tho as I see the same behavior with other calls (ie camera.storage_all) and they return fine.

Environment: