Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
url_override or self.url, headers=headers, verify=self.ssl_verify,
params=params, json=data
)
if req.status_code == 204 and verb == "post":
raise AllocationError(req)
if verb == "delete":
if req.ok:
return True
else:
raise RequestError(req)
elif req.ok:
try:
return req.json()
except json.JSONDecodeError:
raise ContentError(req)
else:
raise RequestError(req)
def __init__(self, message):
req = message
message = (
"The server returned invalid (non-json) data. Maybe not "
"a NetBox server?"
)
super(ContentError, self).__init__(message)
self.req = req
self.request_body = req.request.body
self.base = req.url
self.error = message
"""
req = self.http_session.post(
"{}secrets/get-session-key/?preserve_key=True".format(self.base),
headers={
"accept": "application/json",
"authorization": "Token {}".format(self.token),
"Content-Type": "application/x-www-form-urlencoded",
},
data=urlencode({"private_key": self.private_key.strip("\n")}),
verify=self.ssl_verify,
)
if req.ok:
try:
return req.json()["session_key"]
except json.JSONDecodeError:
raise ContentError(req)
else:
raise RequestError(req)