Merge pull request #1283 from sigmavirus24/master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Closes #1280
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 54ed5ed, b9e5cce · Browse files · 2 files·+37 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+37 added−7 removed
- other:+37 added−7 removed
Provenance
- Commit
dccfc5b- Tree
920ab3f- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
54ed5ed- Parent 2
b9e5cce
2 files changed+37 added−7 removed
modified:docs/user/advanced.rst+35 added-1 removed
73 unmodified lines74 request, and then the request's headers::75 76 >>> r.request.headers77 {'Accept-Encoding': 'identity, deflate, compress, gzip',78- 'Accept': '*/*', 'User-Agent': 'python-requests/0.13.1'}78+ 'Accept': '*/*', 'User-Agent': 'python-requests/1.2.0'}79 80+Prepared Requests81+-----------------82 83+Whenever you receive a :class:`Response <requests.models.Response>` object 84+from an API call or a Session call, the ``request`` attribute is actually the 85+``PreparedRequest`` that was used. In some cases you may wish to do some extra 86+work to the body or headers (or anything else really) before sending a 87+request. The simple recipe for this is the following::88+89+ from requests import Request, Session90+91+ s = Session()92+ prepped = Request('GET', # or any other method, 'POST', 'PUT', etc.93+ url,94+ data=data95+ headers=headers96+ # ...97+ ).prepare()98+ # do something with prepped.body99+ # do something with prepped.headers100+ resp = s.send(prepped,101+ stream=stream,102+ verify=verify,103+ proxies=proxies,104+ cert=cert,105+ timeout=timeout,106+ # etc.107+ )108+ print(resp.status_code)109+110+Since you are not doing anything special with the ``Request`` object, you 111+prepare it immediately and modified the ``PreparedRequest`` object. You then 112+send that with the other parameters you would have sent to ``requests.*`` or 113+``Sesssion.*``. 114+115 SSL Cert Verification116 ---------------------117 118 Requests can verify SSL certificates for HTTPS requests, just like a web browser. To check a host's SSL certificate, you can use the ``verify`` argument::421 unmodified linesmodified:requests/sessions.py+2 added-6 removed
272 unmodified lines273 request.274 :param allow_redirects: (optional) Boolean. Set to True by default.275 :param proxies: (optional) Dictionary mapping protocol to the URL of276 the proxy.277- :param return_response: (optional) If False, an un-sent Request object278- will returned.279- :param config: (optional) A configuration dictionary. See280- ``request.defaults`` for allowed keys and their default values.281- :param prefetch: (optional) whether to immediately download the response282- content. Defaults to ``True``.277+ :param stream: (optional) whether to immediately download the response278+ content. Defaults to ``False``.279 :param verify: (optional) if ``True``, the SSL cert will be verified.280 A CA_BUNDLE path can also be provided.281 :param cert: (optional) if String, path to ssl client cert file (.pem).282 If Tuple, ('cert', 'key') pair.229 unmodified lines