Message232083
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 |
|
Date |
User |
Action |
Args |
2014-12-03 18:45:17 | bastik | set | recipients:
+ bastik, docs@python |
2014-12-03 18:45:17 | bastik | set | messageid: <1417632317.82.0.906874710781.issue22989@psf.upfronthosting.co.za> |
2014-12-03 18:45:17 | bastik | link | issue22989 messages |
2014-12-03 18:45:17 | bastik | create | |
|