Skip to Content
Python in a Nutshell
book

Python in a Nutshell

by Alex Martelli
March 2003
Intermediate to advanced
656 pages
39h 30m
English
O'Reilly Media, Inc.
Content preview from Python in a Nutshell

Name

getresponse

Synopsis

                        h.getresponse( )

Returns an instance r of class HTTPResponse, which represents the response received from the HTTP server. Call after method request has returned. Instance r supplies the following attributes and methods:

r .getheader( name,default =None)

Returns the contents of header name, or default if no such header exists.

r .msg

An instance of class Message of module mimetools, covered in Chapter 21. You can use r .msg to access the response’s headers and body.

r .read( )

Returns a string that is the body of the server’s response.

r .reason

The string that the server gave as the reason for errors or anomalies. If the request was successful, r .reason could, for example, be 'OK‘.

r .status

An integer, the status code that the server returned. If the request was successful, r .status should be between 200 and 299 according to the HTTP standards. Values between 400 and 599 are typical error codes, again according to HTTP standards. For example, 404 is the error code that a server sends when the page you request cannot be found.

r .version

10 if the server supports only HTTP 1.0, 11 if the server supports HTTP 1.1.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python in a Nutshell, 3rd Edition

Python in a Nutshell, 3rd Edition

Alex Martelli, Anna Ravenscroft, Steve Holden
Python in a Nutshell, 4th Edition

Python in a Nutshell, 4th Edition

Alex Martelli, Anna Martelli Ravenscroft, Steve Holden, Paul McGuire
Data Wrangling with Python

Data Wrangling with Python

Jacqueline Kazil, Katharine Jarmul

Publisher Resources

ISBN: 0596001886Supplemental ContentCatalog PageErrata