-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHttpUtil.py
54 lines (48 loc) · 1.77 KB
/
HttpUtil.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
49
50
51
52
53
54
import requests
import json
import os
import time
from logModule import logModule
class HttpUtil:
def __init__(self):
self.url = ""
self.logger = logModule()
def Put(self,url,body,headers):
duration = -1
try:
startTime = time.time()
response = requests.put(url=url,data=body,headers=headers)
self.logger.debug(response.text)
if response.status_code == 200 or response.status_code == 204:
endTime = time.time()
duration = endTime - startTime
self.logger.debug(str(duration))
except Exception as e:
self.logger.error("Error is " + str(e))
return duration
def Get(self,url,headers):
duration = -1
try:
startTime = time.time()
response = requests.get(url=url,headers=headers)
self.logger.debug(response.text)
if response.status_code == 200:
endTime = time.time()
duration = endTime - startTime
self.logger.debug(str(duration))
except Exception as e:
self.logger.error("Error is "+ str(e))
return duration
def Delete(self,url,headers):
duration = -1
try:
startTime = time.time()
response = requests.delete(url=url,headers=headers)
self.logger.debug(response.text)
if response.status_code == 200 or response.status_code == 204:
endTime = time.time()
duration = endTime - startTime
self.logger.debug(str(duration))
except Exception as e:
self.logger.error("Error is " + str(e))
return duration