Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot fails first time #232

Open
rebel2234 opened this issue Oct 18, 2023 · 2 comments
Open

Snapshot fails first time #232

rebel2234 opened this issue Oct 18, 2023 · 2 comments

Comments

@rebel2234
Copy link

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
Copy link
Author

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
Copy link

hsihpder commented Jan 4, 2024

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:

self._token = requests.auth.HTTPBasicAuth(self._user, self._password)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants