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

  1. Prepare the request before sending: prepared = session.prepare_request(Request(...)); session.send(prepared).
  2. Use the higher-level API (session.get/post/etc.) which handles preparation automatically.
  3. 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

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


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)