Added proxy support. Bug fixes in APIHandler. RTSP support (adding)

Proxy support allows contacting the camera behind a proxy (GET and POST requests).
Adding RTSP support - still in progress.
This commit is contained in:
Alano Terblanche
2019-08-11 21:06:21 +02:00
parent 5bc90f7c60
commit 475c72b241
5 changed files with 152 additions and 14 deletions

View File

@@ -1,9 +1,13 @@
import json
import requests
import socket
import socks
class Request:
proxies = None
@staticmethod
def post(url: str, data, params=None) -> requests.Response or None:
@@ -16,10 +20,11 @@ class Request:
"""
try:
headers = {'content-type': 'application/json'}
if params is not None:
r = requests.post(url, params=params, json=data, headers=headers)
else:
r = requests.post(url, json=data)
r = requests.post(url, params=params, json=data, headers=headers, proxies=Request.proxies)
# if params is not None:
# r = requests.post(url, params=params, json=data, headers=headers, proxies=proxies)
# else:
# r = requests.post(url, json=data)
if r.status_code == 200:
return r
else:
@@ -38,7 +43,8 @@ class Request:
:return:
"""
try:
data = requests.get(url=url, params=params, timeout=timeout)
data = requests.get(url=url, params=params, timeout=timeout, proxies=Request.proxies)
return data
except Exception as e:
print("Get Error\n", e)