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

Snapshot fails first time #232

Open rebel2234 opened 10 months ago

rebel2234 commented 10 months ago

Using the get-snapshot.py example I have to run it twice to actually get a snapshot. First time always fails then second and subsequent times will save the snapshot where I have specified. If I wait a minute or so and then try to run it again, the same process is repeated. How do I get it to grab a snapshot without having to run the code twice?

rebel2234 commented 10 months ago
broc@odroid:~$ python3 test.py
Traceback (most recent call last):
  File "/home/broc/.local/lib/python3.10/site-packages/amcrest/http.py", line 150, in _generate_token
    resp = self._command(cmd).content.decode()
  File "/home/broc/.local/lib/python3.10/site-packages/amcrest/http.py", line 317, in _command
    raise LoginError()
amcrest.exceptions.LoginError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/broc/test.py", line 18, in <module>
    camera.snapshot(channel=1, path_file="/home/broc/snapshot_test.jpg")
  File "/home/broc/.local/lib/python3.10/site-packages/amcrest/snapshot.py", line 84, in snapshot
    ret = self.command(cmd, timeout_cmd=timeout, stream=stream)
  File "/home/broc/.local/lib/python3.10/site-packages/amcrest/http.py", line 253, in command
    self._generate_token()
  File "/home/broc/.local/lib/python3.10/site-packages/amcrest/http.py", line 156, in _generate_token
    resp = self._command(cmd).content.decode()
  File "/home/broc/.local/lib/python3.10/site-packages/amcrest/http.py", line 317, in _command
    raise LoginError()
amcrest.exceptions.LoginError
hsihpder commented 8 months ago

Thinking this is because the http module tries Basic auth, then switches to Digest. Could probably set a preferred auth method in the class. That's what I see in wireshark and confirmed here: https://github.com/tchellomello/python-amcrest/blob/3c3fa5855b24a3692ae3bd3a9a335f81cecc999c/src/amcrest/http.py#L147