Open ozikus86 opened 4 years ago
hi there. Try this: import urllib
filename = "/home/pi/Downloads/picture.jpg" #this is where you wanna save de snapshot urllib.urlretrieve(uri, filename) #where the uri is the snapshot link
i hope it helps
nope - MediaUri instance has no attribute 'strip'
sory. i dit sth wrong and corrected it. but i still get"
from requests.auth import HTTPDigestAuth
res=requests.get(url, auth=HTTPDigestAuth('admin', 'admin'))
if res.status_code == 200:
with open('a.jpg', "wb") as fp:
fp.write(res.content)
Hi. Im new to python. Im trying to write a script that connect to camera (dahua) and saves one frame on a local ftp - I succeded but i didint use ONFIV but i captured one frame using RSTP. However it would be very usefull for me to use onvif. Im encountering HTTP_GET request problem. I wrote a code that sendsi mi URI (snapshot link) - when i paste it the browser - i get authentication window - i dont know how to bypass it. Ive been to page 8 google results page (it is considered to be deep web :)) and nothing works. Im sending my code: the problem with authorization 401 i constant. Ive tried everything
rom onvif import ONVIFCamera from PIL import Image import glob, os from requests.auth import HTTPBasicAuth import requests import urllib2 from StringIO import StringIO from base64 import b64encode mycam = ONVIFCamera('192.168.1.108', 80, 'admin', 'admin123','/home/pi/Downloads/onvif-0.2.0/wsdl')
Get Hostname
resp = mycam.devicemgmt.GetHostname() print 'My camera`s hostname: ' + str(resp.Name)
Get system date and time
media=mycam.create_media_service() media_service=mycam.create_media_service() allProfiles=media.GetProfiles() mainProfile=media.GetProfile({'ProfileToken':allProfiles[0]._token}) snapshot=media.GetSnapshotUri({'ProfileToken':mainProfile._token}) uri=snapshot.Uri
s=requests.Session()
s.get(uri,headers={})
auth=HTTPBasicAuth('admin','admin123')
r=requests.get(uri,auth=auth)
s.headers.update({'user':'admin'})
s.headers.update({'password':'admin123'})
print r.status_code
output=requests.post(uri,auth=HTTPBasicAuth('admin','admin123'))
r=s.get(uri)
print output
print uri
userAndPass=b64encode(b"admin:admin123").decode("ascii")
headers={'Authorization':'Basic %s' % userAndPass}
response=requests.get(uri,headers=headers)
print response.status_code
print 'Link do Kamery: '+uri+' '
content=urllib2.urlopen(response).read()
im=Image.open(content)
im.Save('/home/pi/Desktop/test.jpg',"JPEG")