8 examples of 'python requests raise_for_status' in Python

Every line of 'python requests raise_for_status' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
110@staticmethod
111def _raise_for_status(response):
112 """Raises stored :class:`HTTPError`, if one occurred."""
113 http_error_msg = ''
114 if isinstance(response.reason, bytes):
115 try:
116 reason = response.reason.decode('utf-8')
117 except UnicodeDecodeError:
118 reason = response.reason.decode('iso-8859-1')
119 else:
120 reason = response.reason
121
122 if 400 <= response.status_code < 500:
123 http_error_msg = u'%s Client Error: %s for url: %s (%s)' % (response.status_code, reason, response.url, response.content.decode('utf-8'))
124
125 elif 500 <= response.status_code < 600:
126 http_error_msg = u'%s Server Error: %s for url: %s (%s)' % (response.status_code, reason, response.url, response.content.decode('utf-8'))
127
128 if http_error_msg:
129 raise requests.exceptions.HTTPError(http_error_msg, response=response)
12def raise_for_status(r):
13 if r.status_code != requests.codes.ok:
14 error = f'PIC-SURE API reported an error: [{r.status_code}] {r.text}'
15 logger.exception(error)
16 raise RuntimeError(error)
76def raise_for_status(self):
77 self.internal_response.raise_for_status()
27@property
28def status(self):
29 return self.response.status_code
879def raise_for_status(self) -> None:
880 if 400 <= self.status:
881 # reason should always be not None for a started response
882 assert self.reason is not None
883 self.release()
884 raise ClientResponseError(
885 self.request_info,
886 self.history,
887 status=self.status,
888 message=self.reason,
889 headers=self.headers)
229@property
230def status_code(self):
231 """Get status code."""
232 return self.response.status_code
803def check_http_code(self, status, expected_statuses):
804 if status not in expected_statuses:
805 raise RiakError('Expected status %s, received %s' %
806 (expected_statuses, status))
22def test_basic_response(ok_response):
23 response = raise_for_status(ok_response)
24 assert response == ok_response

Related snippets