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 does not work on Amcrest firmware V2.400.AC02.15.R.20170731 #102

Closed
tchellomello opened this issue Jan 7, 2019 · 7 comments
Closed

Comments

@tchellomello
Copy link
Owner

tchellomello commented Jan 7, 2019

Fails on:
2.400.AC01.15.R
2.400.AC02.15.R.20170731

See: #86

@psyciknz
Copy link

Hello, I use a dahua nvr, and where an http call to snapshot.cgi used to work (yes with digest authentication) on an older nvr, I have now replaced it, and the api seems quite different. There was also a call for ConfigManager.cgi&getConfig?name=ChannelTitle that also now fails....but I found in fiddler that there is an RPC2 call that is made now with json that replicates this function, eg:

'{"method":"configManager.getConfig","params":{"name":"ChannelTitle"},"id":51,"session":135423203,"params2":"000001bc3115e090000017d2"}' http://nvrip/RPC2   

Hoping that someone might be interested in working on this, as is may be similar for the snapshot call, that may have moved to the rpc2 method also.....

@pnbruckner
Copy link
Collaborator

I suspect the issues seen here and on #86 have been fixed by HA PRs 21664 & 21720 and amcrest release 1.2.5. FWIW, my camera has version=2.400.AC02.15.R, build:2017-07-31, and it works fine with the above PRs.

@tchellomello
Copy link
Owner Author

tchellomello commented Mar 11, 2019

Hello,

Issue #86

Here is a small snippet using the latest code in master.

93% 2019-03-10 22:48:33 ⌚  p50 in ~/devel/python-amcrest/cli
± |master → origin ✓| → for cam in $(seq 6); do echo "amcrestcam$cam"; 
./amcrest-cli  --camera amcrestcam$cam --device-type; ./amcrest-cli --camera 
amcrestcam$cam --snapshot 1 --save ~/Desktop/image$cam.jpg; file 
~/Desktop/image$cam.jpg; ./amcrest-cli --camera amcrestcam$cam 
--software-information ; echo "===============" ;  done
amcrestcam1
type=IP3M-941W

/home/mdemello/Desktop/image1.jpg: JPEG image data, JFIF standard 1.01, aspect 
ratio, density 1x1, segment length 16, comment: "", comment: "DHAV\373", 
baseline, precision 8, 1280x960, frames 3
('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
===============
amcrestcam2
type=IP2M-841W

/home/mdemello/Desktop/image2.jpg: JPEG image data, JFIF standard 1.01, aspect 
ratio, density 1x1, segment length 16, comment: "", comment: "DHAV\373", 
baseline, precision 8, 1920x1080, frames 3
('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
===============
amcrestcam3
type=IPM-723W

Trying again due to error 401 Client Error: Unauthorized for url: 
http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
Trying again due to error 401 Client Error: Unauthorized for url: 
http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
Trying again due to error 401 Client Error: Unauthorized for url: 
http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
Query failed due to error 401 Client Error: Unauthorized for url: 
http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
Traceback (most recent call last):
  File "./amcrest-cli", line 907, in <module>
    main()
  File "./amcrest-cli", line 898, in main
    camera.snapshot(args.snapshot_option, args.save)
  File 
"/home/mdemello/.virtualenvs/amcrest_dev/local/lib/python3.7/site-packages/
amcrest/snapshot.py", line 48, in snapshot
    timeout_cmd=timeout
  File 
"/home/mdemello/.virtualenvs/amcrest_dev/local/lib/python3.7/site-packages/
amcrest/http.py", line 148, in command
    resp.raise_for_status()
  File 
"/home/mdemello/.virtualenvs/amcrest_dev/local/lib/python3.7/site-packages/
requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: 
http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
/home/mdemello/Desktop/image3.jpg: cannot open 
`/home/mdemello/Desktop/image3.jpg' (No such file or directory)
('version=2.400.AC02.15.R', 'build:2017-07-31\r\n')
===============
amcrestcam4
type=IPM-723W

Trying again due to error 401 Client Error: Unauthorized for url: 
http://amcrestcam4.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
Trying again due to error 401 Client Error: Unauthorized for url: 
http://amcrestcam4.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
Trying again due to error 401 Client Error: Unauthorized for url: 
http://amcrestcam4.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
Query failed due to error 401 Client Error: Unauthorized for url: 
http://amcrestcam4.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
Traceback (most recent call last):
  File "./amcrest-cli", line 907, in <module>
    main()
  File "./amcrest-cli", line 898, in main
    camera.snapshot(args.snapshot_option, args.save)
  File 
"/home/mdemello/.virtualenvs/amcrest_dev/local/lib/python3.7/site-packages/
amcrest/snapshot.py", line 48, in snapshot
    timeout_cmd=timeout
  File 
"/home/mdemello/.virtualenvs/amcrest_dev/local/lib/python3.7/site-packages/
amcrest/http.py", line 148, in command
    resp.raise_for_status()
  File 
"/home/mdemello/.virtualenvs/amcrest_dev/local/lib/python3.7/site-packages/
requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: 
http://amcrestcam4.tatu.home:80/cgi-bin/snapshot.cgi?channel=1
/home/mdemello/Desktop/image4.jpg: cannot open 
`/home/mdemello/Desktop/image4.jpg' (No such file or directory)
('version=2.400.AC02.15.R', 'build:2017-07-31\r\n')
===============
amcrestcam5
type=IP3M-941B

/home/mdemello/Desktop/image5.jpg: JPEG image data, JFIF standard 1.01, aspect 
ratio, density 1x1, segment length 16, comment: "", comment: "DHAV\373", 
baseline, precision 8, 1280x960, frames 3
('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
===============
amcrestcam6
type=IP3M-941W

/home/mdemello/Desktop/image6.jpg: JPEG image data, JFIF standard 1.01, aspect 
ratio, density 1x1, segment length 16, comment: "", comment: "DHAV\373", 
baseline, precision 8, 1280x960, frames 3
('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
===============

So in summary:

worked

type=IP3M-941W - ('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
type=IP2M-841W - ('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
type=IP3M-941B - ('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
type=IP3M-941W - ('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')

failed

type=IPM-723W - ('version=2.400.AC02.15.R', 'build:2017-07-31\r\n')
type=IPM-723W - ('version=2.400.AC02.15.R', 'build:2017-07-31\r\n')

My problem is even if I overwrite the code use Digest, I get the 500 error.

  48         auth = HTTPDigestAuth(self._user, self._password)
  49         ret = requests.get(
  50             
'http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=0',
  51             auth=auth,
  52             stream=True)
  53         import rpdb; rpdb.set_trace()


 !  ~/d/python-amcrest   *srctelnet localhost 4444                   
Sun 10 Mar 2019 11:04:55 PM EDT
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
> /home/mdemello/devel/python-amcrest/src/amcrest/snapshot.py(59)snapshot()
-> if path_file:
(Pdb) l
 54  	        #ret = self.command(
 55  	        #    "snapshot.cgi?channel={0}".format(channel),
 56  	        #    timeout_cmd=timeout
 57  	        #)
 58  	
 59  ->	        if path_file:
 60  	            with open(path_file, 'wb') as out_file:
 61  	                shutil.copyfileobj(ret.raw, out_file)
 62  	
 63  	        return ret.raw
[EOF]
(Pdb) ret
<Response [500]>

@pnbruckner , can you try that on yours?

@tchellomello
Copy link
Owner Author

tchellomello commented Mar 11, 2019

@pnbruckner using the latest merged #108 still the same problem on my camera. Maybe is something with my camera.

In [3]: cam.snapshot(0, '/home/mdemello/Desktop/aa.jpg')                                                         
Trying again due to error 401 Client Error: Unauthorized for url: http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=0
Trying again due to error 401 Client Error: Unauthorized for url: http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=0
Trying again due to error 401 Client Error: Unauthorized for url: http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=0
Query failed due to error 401 Client Error: Unauthorized for url: http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=0
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
~/devel/python-amcrest/src/amcrest/http.py in command(self, cmd, retries, timeout_cmd)
    150                 )
--> 151                 resp.raise_for_status()
    152                 break

~/.virtualenvs/amcrest_dev/local/lib/python3.7/site-packages/requests/models.py in raise_for_status(self)
    939         if http_error_msg:
--> 940             raise HTTPError(http_error_msg, response=self)
    941 

HTTPError: 401 Client Error: Unauthorized for url: http://amcrestcam3.tatu.home:80/cgi-bin/snapshot.cgi?channel=0

During handling of the above exception, another exception occurred:

CommError                                 Traceback (most recent call last)
<ipython-input-3-aa0e95b3b8e8> in <module>
----> 1 cam.snapshot(0, '/home/mdemello/Desktop/aa.jpg')

~/devel/python-amcrest/src/amcrest/snapshot.py in snapshot(self, channel, path_file, timeout)
     46         ret = self.command(
     47             "snapshot.cgi?channel={0}".format(channel),
---> 48             timeout_cmd=timeout
     49         )
     50 

~/devel/python-amcrest/src/amcrest/http.py in command(self, cmd, retries, timeout_cmd)
    157                 else:
    158                     _LOGGER.error("Query failed due to error %s", error)
--> 159                     raise CommError('Could not communicate with camera')
    160 
    161         _LOGGER.debug("Query worked. Exit code: <%s>", resp.status_code)

CommError: Could not communicate with camera

@pnbruckner
Copy link
Collaborator

Using the latest code on master, I could grab snapshots (channels 0 & 1) from both of my cameras. Here is what I did:

(amcrest-test) phil@ha-intel:~/amcrest-test$ ~/repos/python-amcrest/cli/amcrest-cli --camera cam1 --device-type; ~/repos/python-amcrest/cli/amcrest-cli --camera cam1 --software-information; ~/repos/python-amcrest/cli/amcrest-cli --camera cam1 --snapshot 0 --save ~/Pictures/img1-0.jpg; file ~/Pictures/img1-0.jpg
type=IP2M-841W

('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
/home/phil/Pictures/img1-0.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, comment: "", comment: "DHAV\373", baseline, precision 8, 1920x1080, frames 3
(amcrest-test) phil@ha-intel:~/amcrest-test$ ~/repos/python-amcrest/cli/amcrest-cli --camera cam2 --device-type; ~/repos/python-amcrest/cli/amcrest-cli --camera cam2 --software-information; ~/repos/python-amcrest/cli/amcrest-cli --camera cam2 --snapshot 0 --save ~/Pictures/img2-0.jpg; file ~/Pictures/img2-0.jpg
type=IP3M-943W

('version=2.400.AC02.15.R', 'build:2017-07-31\r\n')
/home/phil/Pictures/img2-0.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, comment: "", comment: "DHAV\373", baseline, precision 8, 2304x1296, frames 3
(amcrest-test) phil@ha-intel:~/amcrest-test$ ~/repos/python-amcrest/cli/amcrest-cli --camera cam1 --device-type; ~/repos/python-amcrest/cli/amcrest-cli --camera cam1 --software-information; ~/repos/python-amcrest/cli/amcrest-cli --camera cam1 --snapshot 1 --save ~/Pictures/img1-1.jpg; file ~/Pictures/img1-1.jpg
type=IP2M-841W

('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
/home/phil/Pictures/img1-1.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, comment: "", comment: "DHAV\373", baseline, precision 8, 1920x1080, frames 3
(amcrest-test) phil@ha-intel:~/amcrest-test$ ~/repos/python-amcrest/cli/amcrest-cli --camera cam2 --device-type; ~/repos/python-amcrest/cli/amcrest-cli --camera cam2 --software-information; ~/repos/python-amcrest/cli/amcrest-cli --camera cam2 --snapshot 1 --save ~/Pictures/img2-1.jpg; file ~/Pictures/img2-1.jpg
type=IP3M-943W

('version=2.400.AC02.15.R', 'build:2017-07-31\r\n')
/home/phil/Pictures/img2-1.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, comment: "", comment: "DHAV\373", baseline, precision 8, 2304x1296, frames 3

@pnbruckner
Copy link
Collaborator

Of course, if I shut the stream off, then:

(amcrest-test) phil@ha-intel:~/amcrest-test$ ~/repos/python-amcrest/cli/amcrest-cli --camera cam1 --device-type; ~/repos/python-amcrest/cli/amcrest-cli --camera cam1 --software-information; ~/repos/python-amcrest/cli/amcrest-cli --camera cam1 --snapshot 0 --save ~/Pictures/img1-0.jpg; file ~/Pictures/img1-0.jpg
type=IP2M-841W

('version=2.520.AC00.18.R', 'build:2017-06-29\r\n')
Trying again due to error 401 Client Error: Unauthorized for url: http://pnb.duckdns.org:10002/cgi-bin/snapshot.cgi?channel=0
Trying again due to error 401 Client Error: Unauthorized for url: http://pnb.duckdns.org:10002/cgi-bin/snapshot.cgi?channel=0
Trying again due to error 401 Client Error: Unauthorized for url: http://pnb.duckdns.org:10002/cgi-bin/snapshot.cgi?channel=0
Query failed due to error 401 Client Error: Unauthorized for url: http://pnb.duckdns.org:10002/cgi-bin/snapshot.cgi?channel=0
Traceback (most recent call last):
  File "/home/phil/repos/python-amcrest/src/amcrest/http.py", line 151, in command
    resp.raise_for_status()
  File "/home/phil/amcrest-test/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: http://pnb.duckdns.org:10002/cgi-bin/snapshot.cgi?channel=0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/phil/repos/python-amcrest/cli/amcrest-cli", line 907, in <module>
    main()
  File "/home/phil/repos/python-amcrest/cli/amcrest-cli", line 898, in main
    camera.snapshot(args.snapshot_option, args.save)
  File "/home/phil/repos/python-amcrest/src/amcrest/snapshot.py", line 48, in snapshot
    timeout_cmd=timeout
  File "/home/phil/repos/python-amcrest/src/amcrest/http.py", line 159, in command
    raise CommError('Could not communicate with camera')
amcrest.exceptions.CommError: Could not communicate with camera
/home/phil/Pictures/img1-0.jpg: cannot open `/home/phil/Pictures/img1-0.jpg' (No such file or directory)

@pnbruckner
Copy link
Collaborator

The 1.5.1 release just made should fix these incorrect reports of error 401. However, if the snapshot command doesn't work, there will just be a more reasonable error, which is a connection error. There are two reasons I know of why a snapshot command will fail. The first is trying to issue two snapshot commands simultaneously, e.g., from two different hosts. The one that starts first should succeed, but the second may result in a "connection closed with no response" type error. The other is if the snapshot quality is too high. This I believe can cause an error 500.

Since this issue is fairly old, and there have been several updates to this package, as well as the HA amcrest component, I'm going to close this issue. Feel free to reopen if necessary.

BTW, I'm also working on a new HA amcrest component release that should significantly improve its overall error handling, especially if/when the camera goes "off line."

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

3 participants