-
Notifications
You must be signed in to change notification settings - Fork 4
/
request_handler.py
36 lines (28 loc) · 978 Bytes
/
request_handler.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
import requests
import html
import os
class RequestHandler:
def __init__(self):
self.s = requests.Session()
self.s.cert = (
os.environ["BACKENDCERT"],
os.environ["BACKENDKEY"]
)
self.s.verify = os.environ["BACKENDCA"]
self.root_url = os.environ["BACKENDURL"]
def get(self, url, params):
r = self.s.get(self.root_url+url, params=params)
return html.unescape(r.text)
def put(self, url, params):
r = self.s.put(self.root_url+url, params=params)
return r.text
def post(self, url, params):
r = self.s.post(self.root_url+url, params=params)
return r.text
def upload(self, url, params, filename):
with open(filename, "rb") as f:
r = self.s.put(self.root_url+url, params=params, data=f)
return r.text
def delete(self, url, params):
r = self.s.delete(self.root_url+url, params=params)
return r.text