MCPcopy
hub / github.com/psf/requests / PreparedRequest

Class PreparedRequest

src/requests/models.py:376–727  ·  view source on GitHub ↗

The fully mutable :class:`PreparedRequest <PreparedRequest>` object, containing the exact bytes that will be sent to the server. Instances are generated from a :class:`Request <Request>` object, and should not be instantiated manually; doing so may produce undesirable effects.

Source from the content-addressed store, hash-verified

374
375
376class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
377 """The fully mutable :class:`PreparedRequest <PreparedRequest>` object,
378 containing the exact bytes that will be sent to the server.
379
380 Instances are generated from a :class:`Request <Request>` object, and
381 should not be instantiated manually; doing so may produce undesirable
382 effects.
383
384 Usage::
385
386 >>> import requests
387 >>> req = requests.Request('GET', 'https://httpbin.org/get')
388 >>> r = req.prepare()
389 >>> r
390 <PreparedRequest [GET]>
391
392 >>> s = requests.Session()
393 >>> s.send(r)
394 <Response [200]>
395 """
396
397 method: str | None
398 url: str | None
399 headers: CaseInsensitiveDict[str | bytes]
400 _cookies: RequestsCookieJar | CookieJar | None
401 body: _t.BodyType
402 hooks: dict[str, list[_t.HookType]]
403 _body_position: int | object | None
404
405 def __init__(self) -> None:
406 #: HTTP verb to send to the server.
407 self.method = None
408 #: HTTP URL to send the request to.
409 self.url = None
410 #: dictionary of HTTP headers.
411 self.headers = None # type: ignore[assignment]
412 # The `CookieJar` used to create the Cookie header will be stored here
413 # after prepare_cookies is called
414 self._cookies = None
415 #: request body to send to the server.
416 self.body = None
417 #: dictionary of callback hooks, for internal usage.
418 self.hooks = default_hooks()
419 #: integer denoting starting position of a readable file-like body.
420 self._body_position = None
421
422 def prepare(
423 self,
424 method: str | None = None,
425 url: _t.UriType | None = None,
426 headers: Mapping[str, str | bytes] | None = None,
427 files: _t.FilesType = None,
428 data: _t.DataType = None,
429 params: _t.ParamsType = None,
430 auth: _t.AuthType = None,
431 cookies: RequestsCookieJar | CookieJar | dict[str, str] | None = None,
432 hooks: _t.HooksInputType | None = None,
433 json: _t.JsonType = None,

Callers 7

test_prepared_copyFunction · 0.90
prepareMethod · 0.85
copyMethod · 0.85
prepare_requestMethod · 0.85

Calls

no outgoing calls