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)
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()