How to use the pynetbox.core.query.ContentError function in pynetbox

To help you get started, we’ve selected a few pynetbox examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github digitalocean / pynetbox / pynetbox / core / query.py View on Github external
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)
github digitalocean / pynetbox / pynetbox / core / query.py View on Github external
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
github digitalocean / pynetbox / pynetbox / core / query.py View on Github external
"""
        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)