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
Provenance
- Commit
511b139- Tree
9bbb2f4- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
1d19313- Parent 2
87637c9
2 files changed+80 added−1 removed
modified:docs/user/advanced.rst+79 added-1 removed
43 unmodified lines44 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.45 46 All values that are contained within a session are directly available to you. See the :ref:`Session API Docs <sessionapi>` to learn more.47 48+Request and Response Objects49+----------------------------50 51+Whenever a call is made to requests.*() you are doing two major things. First,52+you are constructing a ``Request`` object which will be sent of to a server53+to request or query some resource. Second, a ``Response`` object is generated54+once ``requests`` gets a response back from the server. The response object 55+contains all of the information returned by the server and also contains the56+``Request`` object you created originally. Here is a simple request to get some57+very important information from Wikipedia's servers::58+ 59+ >>> response = requests.get('http://en.wikipedia.org/wiki/Monty_Python')60+61+If 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'}72+73+However, if we want to get the headers we sent the server, we simply access the74+request, and then the request's headers::75+76+ >>> response.request.headers77+ {'Accept-Encoding': 'identity, deflate, compress, gzip',78+ 'Accept': '*/*', 'User-Agent': 'python-requests/0.13.1'}79+80+Requests have these attributes:81+82+ * 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+ * send108+109+Responses have the following attributes:110+111+ * Variable Attributes112+ * config113+ * cookies114+ * encoding115+ * error116+ * headers117+ * history118+ * raw119+ * request120+ * status_code121+ * url122+ * Class Methods123+ * content124+ * json125+ * raise_for_status126+ * text127+128 SSL Cert Verification129 ---------------------130 131 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::170 unmodified lines302 303 >>> requests.get('http://pizzabin.org/admin', auth=PizzaAuth('kenneth'))304 <Response [200]>305 227-306 Streaming Requests307 ------------------308 309 With ``requests.Response.iter_lines()`` you can easily iterate over streaming222 unmodified linesmodified:AUTHORS.rst+1 added
102 unmodified lines103 - Josh Imhoff <joshimhoff13@gmail.com>104 - Arup Malakar <amalakar@gmail.com>105 - Danilo Bargen (gwrtheyrn)106 - Torsten Landschoff107+- Michael Holler (apotheos)