-
Notifications
You must be signed in to change notification settings - Fork 4
/
url_runner.py
48 lines (39 loc) · 1.38 KB
/
url_runner.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
46
47
48
import requests
import json
session = requests.session()
def get(url, query_data=None, headers=None, return_json=False, keep_alive=True):
if keep_alive:
res = session.get(url, params=query_data, headers=headers)
else:
res = requests.get(url, params=query_data, headers=headers)
if return_json is True:
return res.json()
else:
return res.text
def post(url, data=None, headers=None, return_json=False, keep_alive=True):
if keep_alive:
res = requests.post(url, data=json.dumps(data), headers=headers)
else:
res = session.post(url, data=json.dumps(data), headers=headers)
if return_json is True:
return res.json()
else:
return res.text
def put(url, data=None, headers=None, return_json=False, keep_alive=True):
if keep_alive:
res = requests.put(url, data=json.dumps(data), headers=headers)
else:
res = session.put(url, data=json.dumps(data), headers=headers)
if return_json is True:
return res.json()
else:
return res.text
def delete(url, data=None, headers=None, return_json=False, keep_alive=True):
if keep_alive:
res = requests.delete(url, data=json.dumps(data), headers=headers)
else:
res = session.delete(url, data=json.dumps(data), headers=headers)
if return_json is True:
return res.json()
else:
return res.text