psf/requests · error · ValueError
You can only send PreparedRequests.
Error message
You can only send PreparedRequests.
What it means
Raised by Session.send() when the argument is a Request object instead of a PreparedRequest. The send() method expects a fully prepared request (URL, headers, body all finalized via Session.prepare_request or Request.prepare). Passing an unprepared Request is a common mistake.
Solutions
- Prepare the request before sending: prepared = session.prepare_request(Request(...)); session.send(prepared).
- Use the higher-level API (session.get/post/etc.) which handles preparation automatically.
- Call req.prepare() if you don't have a session context: session.send(Request('GET', url).prepare()).
Example fix
# before
from requests import Request, Session
req = Request('GET', 'https://example.com')
session.send(req) # ValueError
# after
prepared = session.prepare_request(req)
session.send(prepared) Defensive patterns
Strategy: type-guard
Validate before calling
from requests import Request, PreparedRequest
if isinstance(request, Request) and not isinstance(request, PreparedRequest):
request = session.prepare_request(request)
session.send(request) Type guard
from requests import PreparedRequest
def is_prepared(req) -> bool:
return isinstance(req, PreparedRequest) Prevention
- Always call session.prepare_request(req) or req.prepare() before session.send().
- Prefer the high-level session.get/post/put API which handles preparation automatically.
- Understand the distinction: Request is a blueprint, PreparedRequest is ready to transmit.
When it happens
Trigger: Calling session.send(Request(...)) directly instead of session.send(req.prepare()) or session.send(session.prepare_request(req)); confusing the Request class (a blueprint) with PreparedRequest (ready to transmit).
Common situations: New users unfamiliar with the Request/PreparedRequest distinction; building custom request pipelines and forgetting the prepare step; copying code that constructs Request objects without the prepare call.
Related errors
- cannot encode objects that are not 2-tuples
- Exceeded redirects.
- No connection adapters were found for
- ' ' object has no attribute
AI-assisted analysis of psf/requests@8068356288 (2026-08-11).
Data as JSON: /api/errors/f86ed6905d7e9161.
Report an issue: GitHub.
Appendix: source
Thrown at src/requests/sessions.py:768
return self.request("DELETE", url, **kwargs)
def send(self, request: PreparedRequest, **kwargs: Any) -> Response:
"""Send a given PreparedRequest.
:rtype: requests.Response
"""
# Set defaults that the hooks can utilize to ensure they always have
# the correct parameters to reproduce the previous request.
kwargs.setdefault("stream", self.stream)
kwargs.setdefault("verify", self.verify)
kwargs.setdefault("cert", self.cert)
if "proxies" not in kwargs:
kwargs["proxies"] = resolve_proxies(request, self.proxies, self.trust_env)
# It's possible that users might accidentally send a Request object.
# Guard against that specific failure case.
if isinstance(request, Request):
raise ValueError("You can only send PreparedRequests.")
assert _is_prepared(request)
# Set up variables needed for resolve_redirects and dispatching of hooks
allow_redirects = kwargs.pop("allow_redirects", True)
stream = kwargs.get("stream")
hooks = request.hooks
# Get the appropriate adapter to use
adapter = self.get_adapter(url=request.url)
# Start time (approximately) of the request
start = preferred_clock()
# Send the request
r = adapter.send(request, **kwargs)
# Total elapsed time of the request (approximately)View on GitHub (pinned to 8068356288)