From: Martin Panter Date: Thu, 26 Nov 2015 11:01:58 +0000 (+0000) Subject: Issues #22989, #21228: Document HTTP response object for urlopen() X-Git-Tag: v3.4.4rc1~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=747d48cf27e1843f7d1046b4e8127833a40cf9b3;p=python Issues #22989, #21228: Document HTTP response object for urlopen() Previous documentation was not clear if the geturl(), info() and getcode() were valid for HTTP responses. The “msg” attribute is different to the usual HTTPResponse.msg attribute. Based on patch by Evens Fortuné. --- diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst index d98f2005d8..4e595deeb6 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -59,13 +59,7 @@ The :mod:`urllib.request` module defines the following functions: The *cadefault* parameter is ignored. - For http and https urls, this function returns a - :class:`http.client.HTTPResponse` object which has the following - :ref:`httpresponse-objects` methods. - - For ftp, file, and data urls and requests explicitly handled by legacy - :class:`URLopener` and :class:`FancyURLopener` classes, this function - returns a :class:`urllib.response.addinfourl` object which can work as + This function always returns an object which can work as :term:`context manager` and has methods such as * :meth:`~urllib.response.addinfourl.geturl` --- return the URL of the resource retrieved, @@ -77,6 +71,18 @@ The :mod:`urllib.request` module defines the following functions: * :meth:`~urllib.response.addinfourl.getcode` -- return the HTTP status code of the response. + For http and https urls, this function returns a + :class:`http.client.HTTPResponse` object slightly modified. In addition + to the three new methods above, the msg attribute contains the + same information as the :attr:`~http.client.HTTPResponse.reason` + attribute --- the reason phrase returned by server --- instead of + the response headers as it is specified in the documentation for + :class:`~http.client.HTTPResponse`. + + For ftp, file, and data urls and requests explicitly handled by legacy + :class:`URLopener` and :class:`FancyURLopener` classes, this function + returns a :class:`urllib.response.addinfourl` object. + Raises :exc:`~urllib.error.URLError` on errors. Note that ``None`` may be returned if no handler handles the request (though diff --git a/Misc/ACKS b/Misc/ACKS index a0d640d1fa..0f64ef072d 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -436,6 +436,7 @@ Arnaud Fontaine Michael Foord Amaury Forgeot d'Arc Doug Fort +Evens Fortuné Chris Foster John Fouhy Andrew Francis