Author bastik
Recipients bastik, docs@python
Date 2014-12-03.18:45:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1417632317.82.0.906874710781.issue22989@psf.upfronthosting.co.za>
In-reply-to
Content
HTTPResponse.msg is documented as a http.client.HTTPMessage object containing the headers of the response [1].

But in fact this is a string containing the status code:

>>> import urllib.request
>>> req=urllib.request.urlopen('http://heise.de')
>>> content = req.read()
>>> type(req.msg)
<class 'str'>
>>> req.msg
'OK'

This value is apparently overriden in urllib/request.py:

./urllib/request.py:1246:        # This line replaces the .msg attribute of the HTTPResponse
./urllib/request.py-1247-        # with .headers, because urllib clients expect the response to
./urllib/request.py:1248:        # have the reason in .msg.  It would be good to mark this
./urllib/request.py-1249-        # attribute is deprecated and get then to use info() or
./urllib/request.py-1250-        # .headers.
./urllib/request.py:1251:        r.msg = r.reason

Anyhow, it should be documented, that is not safe to retrieve the headers with HTTPResponse.msg and maybe add HTTPResponse.headers to the documentation.

[1] https://docs.python.org/3/library/http.client.html
History
Date User Action Args
2014-12-03 18:45:17bastiksetrecipients: + bastik, docs@python
2014-12-03 18:45:17bastiksetmessageid: <1417632317.82.0.906874710781.issue22989@psf.upfronthosting.co.za>
2014-12-03 18:45:17bastiklinkissue22989 messages
2014-12-03 18:45:17bastikcreate