Skip to content

Commit 747d48c

Browse files
committed
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é.
1 parent 92072ac commit 747d48c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Doc/library/urllib.request.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@ The :mod:`urllib.request` module defines the following functions:
5959

6060
The *cadefault* parameter is ignored.
6161

62-
For http and https urls, this function returns a
63-
:class:`http.client.HTTPResponse` object which has the following
64-
:ref:`httpresponse-objects` methods.
65-
66-
For ftp, file, and data urls and requests explicitly handled by legacy
67-
:class:`URLopener` and :class:`FancyURLopener` classes, this function
68-
returns a :class:`urllib.response.addinfourl` object which can work as
62+
This function always returns an object which can work as
6963
:term:`context manager` and has methods such as
7064

7165
* :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:
7771

7872
* :meth:`~urllib.response.addinfourl.getcode` -- return the HTTP status code of the response.
7973

74+
For http and https urls, this function returns a
75+
:class:`http.client.HTTPResponse` object slightly modified. In addition
76+
to the three new methods above, the msg attribute contains the
77+
same information as the :attr:`~http.client.HTTPResponse.reason`
78+
attribute --- the reason phrase returned by server --- instead of
79+
the response headers as it is specified in the documentation for
80+
:class:`~http.client.HTTPResponse`.
81+
82+
For ftp, file, and data urls and requests explicitly handled by legacy
83+
:class:`URLopener` and :class:`FancyURLopener` classes, this function
84+
returns a :class:`urllib.response.addinfourl` object.
85+
8086
Raises :exc:`~urllib.error.URLError` on errors.
8187

8288
Note that ``None`` may be returned if no handler handles the request (though

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ Arnaud Fontaine
436436
Michael Foord
437437
Amaury Forgeot d'Arc
438438
Doug Fort
439+
Evens Fortuné
439440
Chris Foster
440441
John Fouhy
441442
Andrew Francis

0 commit comments

Comments
 (0)