arduino/Arduino · error · ValueError
You can only send PreparedRequests.
Error message
You can only send PreparedRequests.
What it means
Session.send() only accepts PreparedRequest objects. If the passed object still has a .prepare attribute (i.e. it's an unprepared requests.Request), send raises ValueError, guarding against the common mistake of passing a plain Request.
Source
Thrown at arduino-core/src/processing/app/i18n/python/requests/sessions.py:398
"""
return self.request('PATCH', url, data=data, **kwargs)
def delete(self, url, **kwargs):
"""Sends a DELETE request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
:param \*\*kwargs: Optional arguments that ``request`` takes.
"""
return self.request('DELETE', url, **kwargs)
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)
req = kwargs.pop('req', None)
stream = kwargs.get('stream', False)
timeout = kwargs.get('timeout')
verify = kwargs.get('verify')
cert = kwargs.get('cert')
proxies = kwargs.get('proxies')
hooks = request.hooks
# Get the appropriate adapter to use
adapter = self.get_adapter(url=request.url)
# Start time (approximately) of the request
start = datetime.utcnow()
# Send the requestView on GitHub (pinned to a0df6e0e83)
Solutions
- Call .prepare() on the Request before sending, or use session.request(...) which prepares for you.
- Use requests.PreparedRequest() explicitly and populate prepared fields before send().
- Fix wrapper functions to accept PreparedRequest or call prepare internally.
Example fix
// before
req = requests.Request('GET', 'https://example.com')
session.send(req) # ValueError
// after
req = requests.Request('GET', 'https://example.com').prepare()
session.send(req) Defensive patterns
Strategy: type-guard
Validate before calling
from requests import PreparedRequest
def send_prepared(session, req, **kw):
if not isinstance(req, PreparedRequest):
raise TypeError('send() requires PreparedRequest, got %s' % type(req).__name__)
return session.send(req, **kw) Type guard
from requests import PreparedRequest
def is_prepared(req) -> bool:
return isinstance(req, PreparedRequest) Try / catch
try:
session.send(req, timeout=10)
except ValueError as e:
if 'PreparedRequests' in str(e):
req = req.prepare()
session.send(req, timeout=10)
else:
raise Prevention
- Prefer session.request()/get()/post() which handle preparation automatically.
- In low-level code, always call .prepare() before .send().
- Type-hint helper functions with PreparedRequest to catch mistakes early.
- Add isinstance assertions in wrappers around session.send.
When it happens
Trigger: Calling session.send(request.Request(...)) directly; building a Request manually and forgetting to call Request.prepare() / requests.PreparedRequest; passing the wrong object through wrapper code that forwards to session.send().
Common situations: Low-level usage of requests internals (retry middleware, custom adapters) where authors mix Request and PreparedRequest; copying example code that uses session.send without the preparation step.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- cannot encode objects that are not 2-tuples
- Classes extending RequestMethods must implement their own ``
- stream_decompress mode must be gzip or deflate
- SSLError(e)
- MaxRetryError(self, url, e)
AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06).
Data as JSON: /api/errors/4314081b81e1eb76.
Report an issue: GitHub.