Rewrite get_snap to use requests lib as the old method did not work.
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import io
|
||||
import requests
|
||||
import random
|
||||
import string
|
||||
from urllib import request
|
||||
|
||||
from urllib import parse
|
||||
from io import BytesIO
|
||||
from PIL import Image
|
||||
|
||||
from RtspClient import RtspClient
|
||||
from resthandle import Request
|
||||
|
||||
|
||||
class RecordingAPIMixin:
|
||||
@@ -49,19 +47,19 @@ class RecordingAPIMixin:
|
||||
:param timeout: Request timeout to camera in seconds
|
||||
:return: Image or None
|
||||
"""
|
||||
randomstr = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
|
||||
snap = self.url + "?cmd=Snap&channel=0&rs=" \
|
||||
+ randomstr \
|
||||
+ "&user=" + self.username \
|
||||
+ "&password=" + self.password
|
||||
data = {}
|
||||
data['cmd'] = 'Snap'
|
||||
data['channel'] = 0
|
||||
data['rs'] = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
|
||||
data['user'] = self.username
|
||||
data['password'] = self.password
|
||||
parms = parse.urlencode(data).encode("utf-8")
|
||||
|
||||
try:
|
||||
req = request.Request(snap)
|
||||
req.set_proxy(Request.proxies, 'http')
|
||||
reader = request.urlopen(req, timeout)
|
||||
if reader.status == 200:
|
||||
b = bytearray(reader.read())
|
||||
return Image.open(io.BytesIO(b))
|
||||
print("Could not retrieve data from camera successfully. Status:", reader.status)
|
||||
response = requests.get(self.url, params=parms, timeout=timeout)
|
||||
if response.status_code == 200:
|
||||
return Image.open(BytesIO(response.content))
|
||||
print("Could not retrieve data from camera successfully. Status:", response.stats_code)
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user