10

Is there any chance to get additional status information from my respose object, if a request fails? At this point, I'm able to get the status code, but in addition, I need the status information text (which describes the error). If you're using jQuery ajax, you could get this text from jqXHR's responseText-attribute.

Is there an equivalent for a python-requests response?

rsp = requests.put(url='{0}recorditems/{1}'
                    .format(Utils.configuration['service']['baseURI']
                            , recorditemOID)
                    , data=body
                    , headers=headers
                    , cert=Utils.configuration['daemon']['certFile']
                    , verify=True)

if rsp.status_code == 200:
    Utils.log('Erfassung {0} synchronisiert'.format(recorditemOID))
    return True
else:
    Utils.log('Status-Code -> {0}'.format(rsp.status_code))
Sven Kannenberg
  • 859
  • 2
  • 10
  • 20

2 Answers2

27

Use the Response.reason attribute:

r = requests.get('http://www.google.com/')
print(r.reason)
Lukasa
  • 14,599
  • 4
  • 32
  • 34
0

You can use ResponseHandler class with the return_status() function

response = requests.get('http://www.google.com/')
ResponseHandler(response).return_status()
François B.
  • 1,096
  • 7
  • 19