-
Notifications
You must be signed in to change notification settings - Fork 2
/
requests_wrapper.py
45 lines (40 loc) · 1.43 KB
/
requests_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
from requests.auth import HTTPDigestAuth
class RequestsWrapper:
def __init__(self, mode, ip_base, http_port, theta_id, password):
self.mode = mode
self.theta_id = theta_id
self.theta_password = password
self.ip = ip_base
self.port = http_port
def get(self, url):
try:
if self.mode == "local":
return requests.get(url)
else:
return requests.get(
url,
auth=(HTTPDigestAuth(self.theta_id,
self.theta_password)))
except Exception as e:
print("HTTP Error: {}".format(repr(e)))
return None
def post(self, url, body, stream=False):
try:
if self.mode == "local":
return requests.post(
url,
stream=stream,
data=body,
headers={'Content-Type': 'application/json'})
else:
return requests.post(
url,
stream=stream,
data=body,
headers={'Content-Type': 'application/json'},
auth=(HTTPDigestAuth(self.theta_id,
self.theta_password)))
except Exception as e:
print("HTTP Error: {}".format(repr(e)))
return None