~ubuntu-branches/ubuntu/trusty/python-keystoneclient/trusty-proposed

« back to all changes in this revision

Viewing changes to keystoneclient/exceptions.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-18 07:44:54 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20130118074454-g7w5blpynohn1s48
Tags: 1:0.2.2-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
130
130
def from_response(response, body):
131
131
    """
132
132
    Return an instance of an ClientException or subclass
133
 
    based on an httplib2 response.
 
133
    based on an requests response.
134
134
 
135
135
    Usage::
136
136
 
137
 
        resp, body = http.request(...)
138
 
        if resp.status != 200:
139
 
            raise exception_from_response(resp, body)
 
137
        resp = requests.request(...)
 
138
        if resp.status_code != 200:
 
139
            raise exception_from_response(resp, resp.text)
140
140
    """
141
 
    cls = _code_map.get(response.status, ClientException)
 
141
    cls = _code_map.get(response.status_code, ClientException)
142
142
    if body:
143
143
        if hasattr(body, 'keys'):
144
144
            error = body[body.keys()[0]]
149
149
            # probably couldn't communicate with Keystone at all.
150
150
            message = "Unable to communicate with identity service: %s." % body
151
151
            details = None
152
 
        return cls(code=response.status, message=message, details=details)
 
152
        return cls(code=response.status_code, message=message, details=details)
153
153
    else:
154
 
        return cls(code=response.status)
 
154
        return cls(code=response.status_code)