I have NVR from Dahua, and I have access to admin user on this device.
Using this account I’m trying to get snapshots from IP cameras, connected to this NVR.
According to dahua documentation, to do this, I can use this url link
http://Username:Password@IP-Address/cgi-bin/snapshot.cgi?channel=1
When i replace “username” etc with correct data, it works
I can paste this link in my web browser, and it displays snapshot from chosen camera.
Now I want to do the same in the python code, because those snapshots will be analised by neural network so I need them as python variable not as a picture in my browser.
I wrote some simple code, which looks like this
import requests
from PIL import Image
from io import BytesIO
url = "http://username:password@ip_address/cgi-bin/snapshot.cgi?channel=10"
response = requests.get(url)
if response.status_code == 200:
image = Image.open(BytesIO(response.content))
image.show()
else:
print(f" failed to download the image, respond from website: {response.status_code}")
Obviously I used actual username, not “username”.
And I got error HTTP: 401, which means Unauthorized connection. Which is weird, because if I take this exact url, and copy it from my code to web browser, there is no problem with authorization. Eveything works
I supose that this might be some sort of firewall blockade, or other security stuff happening in NVR configuration, that prevents me from connecting via python code.
I also tried another authentication method, but got the same HTTP 401 respond
session = requests.Session()
session.auth = ('username', 'password')
url = "http://ip_address/cgi-bin/snapshot.cgi?channel=10"
response = session.get(url)
I honestly don’t know. I am Data Scientist, not web developer, nor cybersecurity expert, so my knowledge in these areas is very limited