Merge pull request #1119 from Lukasa/diags

Better diagnostics when trying to send unprepared request
This commit is contained in:
Kenneth Reitz
2013-02-10 14:06:38 -08:00
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -365,6 +365,11 @@ class Session(SessionRedirectMixin):
def send(self, request, **kwargs):
"""Send a given PreparedRequest."""
# It's possible that users might accidentally send a Request object.
# Guard against that specific failure case.
if getattr(request, 'prepare', None):
raise ValueError('You can only send PreparedRequests.')
# Set up variables needed for resolve_redirects and dispatching of
# hooks
allow_redirects = kwargs.pop('allow_redirects', True)
+4
View File
@@ -341,5 +341,9 @@ class RequestsTestCase(unittest.TestCase):
self.assertEqual(('user', 'pass'),
requests.utils.get_auth_from_url(url))
def test_cannot_send_unprepared_requests(self):
r = requests.Request(url=HTTPBIN)
self.assertRaises(ValueError, requests.Session().send, r)
if __name__ == '__main__':
unittest.main()