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
216 stars 76 forks source link

AD410 400 Error #177

Open edk4971 opened 3 years ago

edk4971 commented 3 years ago

Hello, Tried to use the get-files.py example, and it threw a 400 Client Error: $ python3 /home/elliott/get-files.py

Trying again due to error: HTTPError('400 Client Error: Bad Request for url: http://192.168.2.145:80/cgi-bin/mediaFileFind.cgi?action=findFile&object=1831397672&condition.Channel=0&condition.StartTime=2021-07-10%2001:20:15.936236&condition.EndTime=2021-07-10%2007:20:15.936236') Trying again due to error: HTTPError('400 Client Error: Bad Request for url: http://192.168.2.145:80/cgi-bin/mediaFileFind.cgi?action=findFile&object=1831397672&condition.Channel=0&condition.StartTime=2021-07-10%2001:20:15.936236&condition.EndTime=2021-07-10%2007:20:15.936236') Trying again due to error: HTTPError('400 Client Error: Bad Request for url: http://192.168.2.145:80/cgi-bin/mediaFileFind.cgi?action=findFile&object=1831397672&condition.Channel=0&condition.StartTime=2021-07-10%2001:20:15.936236&condition.EndTime=2021-07-10%2007:20:15.936236') Traceback (most recent call last): File "/home/elliott/.local/lib/python3.8/site-packages/amcrest/http.py", line 204, in _command resp.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://192.168.2.145:80/cgi-bin/mediaFileFind.cgi?action=findFile&object=1831397672&condition.Channel=0&condition.StartTime=2021-07-10%2001:20:15.936236&condition.EndTime=2021-07-10%2007:20:15.936236 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/elliott/get-files.py", line 23, in for text in camera.find_files(start_time, end_time): File "/home/elliott/.local/lib/python3.8/site-packages/amcrest/media.py", line 134, in find_files search = self.media_file_find_start( File "/home/elliott/.local/lib/python3.8/site-packages/amcrest/media.py", line 88, in media_file_find_start ret = self.command( File "/home/elliott/.local/lib/python3.8/site-packages/amcrest/http.py", line 169, in command return self._command(*args, **kwargs) File "/home/elliott/.local/lib/python3.8/site-packages/amcrest/http.py", line 209, in _command raise CommError(error) amcrest.exceptions.CommError: 400 Client Error: Bad Request for url: http://192.168.2.145:80/cgi-bin/mediaFileFind.cgi?action=findFile&object=1831397672&condition.Channel=0&condition.StartTime=2021-07-10%2001:20:15.936236&condition.EndTime=2021-07-10%2007:20:15.936236
wizmo2 commented 3 years ago

You might want to try using Channel 1 (add ",1" to the file_find function).

I've made some changes to media.py to get it working on my IP5M-B1186EW as there are some other issues against the latest API documentation, namely

@tchellomello, Not sure how the changes apply to backward compatibility. Do you want me to issue a PR for review?

maximvelichko commented 1 year ago

@wizmo2 , changing to action=close and action=destroy resolved the issue for me. Can you make a PR for that? (Or I can do it)

What is weird, I definitely remember that factory.close and factory.destroy worked for me (~2 years ago). But not now. I am not sure what changed (my Amcrest camera is still the same).

Does it make sense to do:

try:
        ret = self.command(
            f"mediaFileFind.cgi?action=close&object={factory_id}"
        )
except:
        ret = self.command(
            f"mediaFileFind.cgi?action=factory.close&object={factory_id}"
        )

?

wizmo2 commented 1 year ago

@maximvelichko, This was I while ago that I looked at this. It would take me a while to go back and see what I did, so go ahead with your own PR.