summaryrefslogtreecommitdiff
path: root/docs/user
diff options
context:
space:
mode:
authorCory Benfield <lukasaoz@gmail.com>2013-10-24 21:14:46 +0100
committerCory Benfield <lukasaoz@gmail.com>2013-10-24 21:14:46 +0100
commite8683f00a601a59e971e5a31dbb4328f7e5d4acb (patch)
tree666bdf59855f2973977f08b72d311cf08230046d /docs/user
parent7b5c11f66bf22a31f1ee32999c5bb460caaa1be5 (diff)
downloadpython-requests-e8683f00a601a59e971e5a31dbb4328f7e5d4acb.tar.gz
Improve the PreparedRequest docs.
Diffstat (limited to 'docs/user')
-rw-r--r--docs/user/advanced.rst30
1 files changed, 30 insertions, 0 deletions
diff --git a/docs/user/advanced.rst b/docs/user/advanced.rst
index 386e7ddc..14e9ac3f 100644
--- a/docs/user/advanced.rst
+++ b/docs/user/advanced.rst
@@ -112,6 +112,36 @@ prepare it immediately and modified the ``PreparedRequest`` object. You then
send that with the other parameters you would have sent to ``requests.*`` or
``Sesssion.*``.
+However, the above code will lose some of the advantages of having a Requests
+:class:`Session <requests.Session>` object. In particular,
+:class:`Session <requests.Session>`-level state such as cookies will
+not get applied to your request. To get a
+:class:`PreparedRequest <requests.models.PreparedRequest>` with that state
+applied, replace the call to ``Request.prepare()`` with a call to
+``Session.prepare_request()``, like this::
+
+ from requests import Request, Session
+
+ s = Session()
+ req = Request('GET', # or any other method, 'POST', 'PUT', etc.
+ url,
+ data=data
+ headers=headers
+ # ...
+ )
+ prepped = s.prepare_request(req)
+ # do something with prepped.body
+ # do something with prepped.headers
+ resp = s.send(prepped,
+ stream=stream,
+ verify=verify,
+ proxies=proxies,
+ cert=cert,
+ timeout=timeout,
+ # etc.
+ )
+ print(resp.status_code)
+
SSL Cert Verification
---------------------