Skip to content
Myr

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

2 files+37 added−7 removed

modified:docs/user/advanced.rst+35 added-1 removed
73 unmodified lines
74request, and then the request's headers::7576 >>> 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'}7980Prepared Requests81-----------------8283Whenever you receive a :class:`Response <requests.models.Response>` object 84from 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 86work to the body or headers (or anything else really) before sending a 87request. The simple recipe for this is the following::8889 from requests import Request, Session9091 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)109110Since you are not doing anything special with the ``Request`` object, you 111prepare it immediately and modified the ``PreparedRequest`` object. You then 112send that with the other parameters you would have sent to ``requests.*`` or 113``Sesssion.*``. 114115SSL Cert Verification116---------------------117118Requests 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 lines
modified:requests/sessions.py+2 added-6 removed
272 unmodified lines
273 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