Skip to content
Myr

Merge branch 'httperror_init' of git://github.com/dmedvinsky/requests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Conflicts: AUTHORS.rst test_requests.py

authored by Kenneth Reitz · committed by Kenneth Reitz · parents b14584f, c4f9340 · Browse files · 4 files+39 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+39 added−4 removed

  • other:+39 added−4 removed

4 files+39 added−4 removed

modified:requests/exceptions.py+5 added-1 removed
14 unmodified lines
151617class HTTPError(RequestException):18 """An HTTP error occurred."""19 response = None1920 def __init__(self, *args, **kwargs):21 """ Initializes HTTPError with optional `response` object. """22 self.response = kwargs.pop('response', None)23 super(HTTPError, self).__init__(*args, **kwargs)242526class ConnectionError(RequestException):27 """A Connection error occurred."""2829
26 unmodified lines
modified:requests/models.py+1 added-3 removed
655 unmodified lines
656 elif 500 <= self.status_code < 600:657 http_error_msg = '%s Server Error: %s' % (self.status_code, self.reason)658659 if http_error_msg:660 http_error = HTTPError(http_error_msg)661 http_error.response = self662 raise http_error660 raise HTTPError(http_error_msg, response=self)661662 def close(self):663 return self.raw.release_conn()
modified:AUTHORS.rst+2 added
119 unmodified lines
120- David Bonner <dbonner@gmail.com> @rascalking121- Vinod Chandru122- Johnny Goodnow <j.goodnow29@gmail.com>123- Denis Ryzhkov <denisr@denisr.com>124- Wilfred Hughes <me@wilfred.me.uk> @dontYetKnow125- Dmitry Medvinsky <me@dmedvinsky.name>
modified:test_requests.py+31 added
364 unmodified lines
365 def test_cannot_send_unprepared_requests(self):366 r = requests.Request(url=HTTPBIN)367 self.assertRaises(ValueError, requests.Session().send, r)368369 def test_can_specify_retries(self):370 # monkey patch urlopen371 from requests.packages.urllib3.poolmanager import HTTPConnectionPool372 old_urlopen = HTTPConnectionPool.urlopen373374 max_retries_used = []375 def urlopen(*args, **kwargs):376 """Save what value we used for retries each time we call urlopen."""377 max_retries_used.append(kwargs.get('retries'))378 return old_urlopen(*args, **kwargs)379380 HTTPConnectionPool.urlopen = urlopen381382 # do the request and check that max_retries was passed through383 requests.get(httpbin('get'), max_retries=5)384 self.assertEqual(max_retries_used, [5])385386 # undo monkey patch387 HTTPConnectionPool.urlopen = old_urlopen388389 def test_http_error(self):390 error = requests.exceptions.HTTPError()391 self.assertEqual(error.response, None)392 response = requests.Response()393 error = requests.exceptions.HTTPError(response=response)394 self.assertEqual(error.response, response)395 error = requests.exceptions.HTTPError('message', response=response)396 self.assertEqual(str(error), 'message')397 self.assertEqual(error.response, response)398399400if __name__ == '__main__':401 unittest.main()