Skip to content
Myr

Merge pull request #676 from apotheos/develop

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Additional Documentation for Requests and Responses

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 1d19313, 87637c9 · Browse files · 2 files+80 added−1 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+80 added−1 removed

  • other:+80 added−1 removed

2 files+80 added−1 removed

modified:docs/user/advanced.rst+79 added-1 removed
43 unmodified lines
44 Sometimes you'll want to omit session-level keys from a dict parameter. To do this, you simply set that key's value to ``None`` in the method-level parameter. It will automatically be omitted.4546All values that are contained within a session are directly available to you. See the :ref:`Session API Docs <sessionapi>` to learn more.4748Request and Response Objects49----------------------------5051Whenever a call is made to requests.*() you are doing two major things. First,52you are constructing a ``Request`` object which will be sent of to a server53to request or query some resource. Second, a ``Response`` object is generated54once ``requests`` gets a response back from the server. The response object 55contains all of the information returned by the server and also contains the56``Request`` object you created originally. Here is a simple request to get some57very important information from Wikipedia's servers::58 59 >>> response = requests.get('http://en.wikipedia.org/wiki/Monty_Python')6061If we want to access the headers the server sent back to us, we do this::62 63 >>> response.headers64 {'content-length': '56170', 'x-content-type-options': 'nosniff', 'x-cache':65 'HIT from cp1006.eqiad.wmnet, MISS from cp1010.eqiad.wmnet', 'content-encoding': 66 'gzip', 'age': '3080', 'content-language': 'en', 'vary': 'Accept-Encoding,Cookie',67 'server': 'Apache', 'last-modified': 'Wed, 13 Jun 2012 01:33:50 GMT',68 'connection': 'close', 'cache-control': 'private, s-maxage=0, max-age=0,69 must-revalidate', 'date': 'Thu, 14 Jun 2012 12:59:39 GMT', 'content-type':70 'text/html; charset=UTF-8', 'x-cache-lookup': 'HIT from cp1006.eqiad.wmnet:3128,71 MISS from cp1010.eqiad.wmnet:80'}7273However, if we want to get the headers we sent the server, we simply access the74request, and then the request's headers::7576 >>> response.request.headers77 {'Accept-Encoding': 'identity, deflate, compress, gzip',78 'Accept': '*/*', 'User-Agent': 'python-requests/0.13.1'}7980Requests have these attributes:8182 * Variable Attributes83 * allow_redirects84 * auth85 * cert86 * config87 * cookies88 * data89 * files90 * headers91 * hooks92 * method93 * params94 * prefetch95 * proxies96 * redirect97 * response98 * sent99 * session100 * timeout101 * url102 * Class Methods103 * deregister_hook104 * full_url105 * path_url106 * register_hook107 * send108109Responses have the following attributes:110111 * Variable Attributes112 * config113 * cookies114 * encoding115 * error116 * headers117 * history118 * raw119 * request120 * status_code121 * url122 * Class Methods123 * content124 * json125 * raise_for_status126 * text127128SSL Cert Verification129---------------------130131Requests 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::
170 unmodified lines
302303 >>> requests.get('http://pizzabin.org/admin', auth=PizzaAuth('kenneth'))304 <Response [200]>305227306Streaming Requests307------------------308309With ``requests.Response.iter_lines()`` you can easily iterate over streaming
222 unmodified lines
modified:AUTHORS.rst+1 added
102 unmodified lines
103- Josh Imhoff <joshimhoff13@gmail.com>104- Arup Malakar <amalakar@gmail.com>105- Danilo Bargen (gwrtheyrn)106- Torsten Landschoff107- Michael Holler (apotheos)