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.

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.