diff --git a/requests/sessions.py b/requests/sessions.py index 0fad2543a0..45be9733e5 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -557,7 +557,7 @@ def send(self, request, **kwargs): # It's possible that users might accidentally send a Request object. # Guard against that specific failure case. - if not isinstance(request, PreparedRequest): + if isinstance(request, Request): raise ValueError('You can only send PreparedRequests.') # Set up variables needed for resolve_redirects and dispatching of hooks diff --git a/tests/test_requests.py b/tests/test_requests.py index ebef0ba37d..2614667442 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -638,6 +638,14 @@ def test_unicode_method_name_with_request_object(self, httpbin): resp = s.send(prep) assert resp.status_code == 200 + def test_non_prepared_request_error(self): + s = requests.Session() + req = requests.Request(u('POST'), '/') + + with pytest.raises(ValueError) as e: + s.send(req) + assert str(e.value) == 'You can only send PreparedRequests.' + def test_custom_content_type(self, httpbin): r = requests.post( httpbin('post'),