Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPResponse.msg not as documented #67178

Closed
bastik mannequin opened this issue Dec 3, 2014 · 5 comments
Closed

HTTPResponse.msg not as documented #67178

bastik mannequin opened this issue Dec 3, 2014 · 5 comments
Labels
docs Documentation in the Doc dir

Comments

@bastik
Copy link
Mannequin

bastik mannequin commented Dec 3, 2014

BPO 22989
Nosy @bitdancer, @vadmium

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-11-26.11:19:03.673>
created_at = <Date 2014-12-03.18:45:17.797>
labels = ['docs']
title = 'HTTPResponse.msg not as documented'
updated_at = <Date 2015-11-26.11:19:03.645>
user = 'https://bugs.python.org/bastik'

bugs.python.org fields:

activity = <Date 2015-11-26.11:19:03.645>
actor = 'martin.panter'
assignee = 'docs@python'
closed = True
closed_date = <Date 2015-11-26.11:19:03.673>
closer = 'martin.panter'
components = ['Documentation']
creation = <Date 2014-12-03.18:45:17.797>
creator = 'bastik'
dependencies = []
files = []
hgrepos = []
issue_num = 22989
keywords = []
message_count = 5.0
messages = ['232083', '232224', '234943', '255406', '255408']
nosy_count = 5.0
nosy_names = ['r.david.murray', 'docs@python', 'python-dev', 'martin.panter', 'bastik']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue22989'
versions = ['Python 3.4', 'Python 3.5', 'Python 3.6']

@bastik
Copy link
Mannequin Author

bastik mannequin commented Dec 3, 2014

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

@bastik bastik mannequin assigned docspython Dec 3, 2014
@bastik bastik mannequin added the docs Documentation in the Doc dir label Dec 3, 2014
@vadmium
Copy link
Member

vadmium commented Dec 5, 2014

See bpo-21228 for a patch which documents the “.msg” hack, and that the info() method is available for HTTP responses.

I think documenting the “.headers” attribute would be a bad idea, because it is introducing yet another way to do what the almost-documented info() method already does.

@vadmium
Copy link
Member

vadmium commented Jan 29, 2015

Documenting the “headers” attribute is also discussed in bpo-12707

@python-dev
Copy link
Mannequin

python-dev mannequin commented Nov 26, 2015

New changeset fa3c9faabfb0 by Martin Panter in branch '3.4':
Issues bpo-22989, bpo-21228: Document HTTP response object for urlopen()
https://hg.python.org/cpython/rev/fa3c9faabfb0

New changeset b55c006b79bc by Martin Panter in branch '3.5':
Issue bpo-22989, bpo-21228: Merge urlopen() doc from 3.4 into 3.5
https://hg.python.org/cpython/rev/b55c006b79bc

New changeset c6930661599b by Martin Panter in branch 'default':
Issue bpo-22989, bpo-21228: Merge urlopen() doc from 3.5
https://hg.python.org/cpython/rev/c6930661599b

@vadmium
Copy link
Member

vadmium commented Nov 26, 2015

The documentation now mentions the “msg” quirk and the info() method.

@vadmium vadmium closed this as completed Nov 26, 2015
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

1 participant