-
Notifications
You must be signed in to change notification settings - Fork 0
/
HttpRequestFunction.py
53 lines (44 loc) · 1.52 KB
/
HttpRequestFunction.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
import requests
import json
keyPath = ""
certPath = ""
#Preload keypath and certPath
def httpRequestInit():
global keyPath, certPath
config = loadFile("config.json")
config = json.loads(config)
keyPath = config["keyPath"]
certPath = config["certPath"]
def getHttpRequest(request_url):
response = requests.get(request_url, cert = (certPath,keyPath))
#printResponse(response)
return response
#payload must not be in Bytes
def postHttpRequest(request_url, payload):
print("Post Http Request")
response = requests.post(request_url, data = payload,cert = (certPath,keyPath))
print(response.status_code)
printResponse(response)
print(response.status_code)
return response
#payload must not be in Bytes
#Reminder: doEncryption Function return in Byte
#Use this if Encryption is needed
def postHttpRequestJson(request_url, payload):
print("Post Http Request")
response = requests.post(request_url, json = payload,cert = (certPath,keyPath))
#printResponse(response)
return response
def loadFile(payloadFileName):
global payload
#This is a template to load the file
courseRunPayload = open(payloadFileName, "r")
payload = courseRunPayload.read()
return payload
def saveJsonFormat(content, fileName):
with open(fileName, 'w') as f:
json.dump(content, f, indent=4)
def printResponse(response):
print("Status Code: ", response.status_code)
print(response.text)
httpRequestInit()