{"record":{"id":"f86ed6905d7e9161","repo":"psf/requests","slug":"you-can-only-send-preparedrequests","errorCode":null,"errorMessage":"You can only send PreparedRequests.","messagePattern":"You can only send PreparedRequests\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/requests/sessions.py","lineNumber":768,"sourceCode":"        return self.request(\"DELETE\", url, **kwargs)\n\n    def send(self, request: PreparedRequest, **kwargs: Any) -> Response:\n        \"\"\"Send a given PreparedRequest.\n\n        :rtype: requests.Response\n        \"\"\"\n        # Set defaults that the hooks can utilize to ensure they always have\n        # the correct parameters to reproduce the previous request.\n        kwargs.setdefault(\"stream\", self.stream)\n        kwargs.setdefault(\"verify\", self.verify)\n        kwargs.setdefault(\"cert\", self.cert)\n        if \"proxies\" not in kwargs:\n            kwargs[\"proxies\"] = resolve_proxies(request, self.proxies, self.trust_env)\n\n        # It's possible that users might accidentally send a Request object.\n        # Guard against that specific failure case.\n        if isinstance(request, Request):\n            raise ValueError(\"You can only send PreparedRequests.\")\n\n        assert _is_prepared(request)\n\n        # Set up variables needed for resolve_redirects and dispatching of hooks\n        allow_redirects = kwargs.pop(\"allow_redirects\", True)\n        stream = kwargs.get(\"stream\")\n        hooks = request.hooks\n\n        # Get the appropriate adapter to use\n        adapter = self.get_adapter(url=request.url)\n\n        # Start time (approximately) of the request\n        start = preferred_clock()\n\n        # Send the request\n        r = adapter.send(request, **kwargs)\n\n        # Total elapsed time of the request (approximately)","sourceCodeStart":750,"sourceCodeEnd":786,"githubUrl":"https://github.com/psf/requests/blob/8068356288978c4f54661ae6f95afe0e0831885e/src/requests/sessions.py#L750-L786","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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())."],"exampleFix":"# before\nfrom requests import Request, Session\nreq = Request('GET', 'https://example.com')\nsession.send(req)  # ValueError\n\n# after\nprepared = session.prepare_request(req)\nsession.send(prepared)","handlingStrategy":"type-guard","validationCode":"from requests import Request, PreparedRequest\nif isinstance(request, Request) and not isinstance(request, PreparedRequest):\n    request = session.prepare_request(request)\nsession.send(request)","typeGuard":"from requests import PreparedRequest\ndef is_prepared(req) -> bool:\n    return isinstance(req, PreparedRequest)","tryCatchPattern":null,"preventionTips":["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."],"tags":["session","prepared-request","api-misuse","value-error"],"backgroundTag":null,"analyzedSha":"8068356288978c4f54661ae6f95afe0e0831885e","analyzedAt":"2026-08-11T20:11:09.238Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}