Reputation: 43
I have a python script that downloads a snapshot from a camera. I use auth to login to the camera. For older style cameras it works with no issues, with the new one it doesn't. I have tested the link and credentials by copying them from my python script to make sure they work and they do, but i still can't login and I am not sure why. The commented url is the one that works. The uniview one doesn't. I have replaced the password with the correct one and i also tested the link in Chromium and it works.
import requests
#hikvision old cameras
#url = 'http://192.168.100.110/ISAPI/Streaming/channels/101/picture'
#uniview
url = 'http://192.168.100.108:85/images/snapshot.jpg'
r = requests.get(url, auth=('admin','password'))
if r.status_code == 200:
with open('/home/pi/Desktop/image.jpg', 'wb') as out:
for bits in r.iter_content():
out.write(bits)
else:
print(r.status_code)
print(r.content)
Below is the response I get
b'{\r\n"Response": {\r\n\t"ResponseURL": "/images/snapshot.jpg",\r\n\t"ResponseCode": 3,\r\n \t"SubResponseCode": 0,\r\n \t"ResponseString": "Not Authorized",\r\n\t"StatusCode": 401,\r\n\t"StatusString": "Unauthorized",\r\n\t"Data": "null"\r\n}\r\n}\r\n'
Upvotes: 3
Views: 781
Reputation: 4679
So it looks like hikvisio
are using Basic_access_authentication while uniview
are using Digest_access_authentication so according to the docs you need to change your request to:
from requests.auth import HTTPDigestAuth
r = requests.get(url, auth=HTTPDigestAuth('admin','password'))
Upvotes: 2