This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: urllib 'headers' is not a well defined data type
Type: behavior Stage: resolved
Components: Versions:
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: demian.brecht, r.david.murray
Priority: normal Keywords:

Created on 2014-03-13 15:27 by r.david.murray, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg213406 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-13 15:27
Some places in the code it is an email.message.Message object.  Some places it is a simple dictionary.  In one place (FTP), it is a string with embedded newlines.

I'm not sure what should be done about this situation, but it looks like a bug magnet, and it makes it pretty much impossible to document the data type.
msg237381 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2015-03-06 21:05
@Demian I believe this maybe of interest to you.
msg334246 - (view) Author: Demian Brecht (demian.brecht) * (Python triager) Date: 2019-01-23 03:50
@R. David Murray

Is this issue still valid? Running 3.6 it seems that http and ftp are consistent at any rate (http returns http.client.HTTPMessage and ftp returns email.message.Message). If it's still an issue, could you please elaborate?
msg334270 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2019-01-23 20:18
There has been considerable rewriting of the header handling code since I filed this.  I would not be surprised if the issue is no longer valid.  If you want to double check, look for the places that the headers attribute is created in the various handlers.  Otherwise you can just close this as out of date.
msg334327 - (view) Author: Demian Brecht (demian.brecht) * (Python triager) Date: 2019-01-24 23:51
>>> urlopen('').info()
<http.client.HTTPMessage object at 0x111528da0>
>>> urlopen('').info()
<http.client.HTTPMessage object at 0x111528be0>
>>> urlopen('').info()
<email.message.Message object at 0x111531080>
>>> urlopen('file:///path/to/').info()
<email.message.Message object at 0x111528f60>

I've taken a look at the rest of the handlers in urllib.request and they all build headers consistently with email.message_from_string().

Closing as out of date.
Date User Action Args
2022-04-11 14:57:59adminsetgithub: 65110
2019-01-24 23:51:33demian.brechtsetstatus: open -> closed
resolution: out of date
messages: + msg334327

stage: resolved
2019-01-23 20:18:43r.david.murraysetmessages: + msg334270
2019-01-23 11:48:52BreamoreBoysetnosy: - BreamoreBoy
2019-01-23 03:50:39demian.brechtsetmessages: + msg334246
2015-03-06 21:05:14BreamoreBoysetnosy: + demian.brecht, BreamoreBoy
messages: + msg237381
2014-03-13 15:27:34r.david.murraycreate