-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathjsonRequest.py
More file actions
30 lines (25 loc) · 916 Bytes
/
jsonRequest.py
File metadata and controls
30 lines (25 loc) · 916 Bytes
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
import logging
from htpclient.config import Config
from htpclient.session import Session
class JsonRequest:
def __init__(self, data):
self.data = data
self.config = Config()
self.session = Session().s
def execute(self, ignore_certificate: bool = True):
try:
logging.debug(self.data)
r = self.session.post(
self.config.get_value('url'),
json=self.data,
timeout=30,
verify=not ignore_certificate,
allow_redirects=True)
if r.status_code != 200:
logging.error("Status code from server: " + str(r.status_code))
return None
logging.debug(r.content)
return r.json()
except Exception as e:
logging.error("Error occurred: " + str(e))
return None