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))
The Status-Code element in a server response, is a 3-digit integer where the first digit of the Status-Code defines the class of response and the last two digits do not have any categorization role. There are 5 values for the first digit: S.N. It means the request has been received and the process is continuing.
The HTTP 200 OK success status response code indicates that the request has succeeded. A 200 response is cacheable by default.
The origin server MUST create the resource before returning the 201 status code. If the action cannot be carried out immediately, the server SHOULD respond with 202 (Accepted) response instead.
If you pick up the result from when you post you can then check the status code: result = Session. post(SubmitURL, data=PostData) if result. status_code == requests.
Use the Response.reason
attribute:
r = requests.get('http://www.google.com/')
print(r.reason)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With