requests.codes.UNAUTHORIZED

Here are the examples of the python api requests.codes.UNAUTHORIZED taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: gitem Source File: api.py
Function: unauthorized
    @property
    def unauthorized(self):
        return self.code == requests.codes.UNAUTHORIZED

Example 2

Project: networking-cisco Source File: cisco_csr_rest_client.py
    def _do_request(self, method, resource, payload=None, more_headers=None,
                    full_url=False):
        """Perform a REST request to a CSR resource.

        If this is the first time interacting with the CSR, a token will
        be obtained. If the request fails, due to an expired token, the
        token will be obtained and the request will be retried once more.
        """

        if self.token is None:
            if not self.authenticate():
                return

        if full_url:
            url = resource
        else:
            url = ('https://%(host)s/api/v1/%(resource)s' %
                   {'host': self.host, 'resource': resource})
        headers = {'Accept': 'application/json', 'X-auth-token': self.token}
        if more_headers:
            headers.update(more_headers)
        if payload:
            payload = jsonutils.dumps(payload)
        response = self._request(method, url, data=payload, headers=headers)
        if self.status == requests.codes.UNAUTHORIZED:
            if not self.authenticate():
                return
            headers['X-auth-token'] = self.token
            response = self._request(method, url, data=payload,
                                     headers=headers)
        if self.status != requests.codes.REQUEST_TIMEOUT:
            return response
        LOG.error(_LE("%(method)s: Request timeout for CSR(%(host)s)"),
                  {'method': method, 'host': self.host})