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.

classification
Title: urllib2 changes header names
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, jedie, jjlee, vimico
Priority: normal Keywords:

Created on 2006-03-28 12:02 by vimico, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg27914 - (view) Author: Michael Vert (vimico) Date: 2006-03-28 12:02
It seems that urllib2 changes the writing of any
additional supplied headers, i.e. "User-Agent" becomes
"User-agent", "TEST-HEADER" becomes "Test-header".

A few sites do not recognize "User-agent" and insist on
"User-Agent".

Fix: remove all occurences of capitalize() in urllib2.
msg27915 - (view) Author: Jens Diemer (jedie) Date: 2006-03-28 12:16
Logged In: YES 
user_id=1330780

There are old, closed Bug-Reports:
https://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=994101

?!?!?
msg27916 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-03-28 12:40
Logged In: YES 
user_id=849994

Some normalizing is important to prevent duplicate headers.
Changed capitalize() to title() to match the default casing
(now user-agent becomes User-Agent) in rev. 43399.
msg27917 - (view) Author: Michael Vert (vimico) Date: 2006-03-28 15:32
Logged In: YES 
user_id=928834

I checked the database before submitting...  I admit, I
haven't gone back 2 years. :-)

It seems to be the same bug. But it was still present in
2.4.2 (version used in Ubuntu Breezy).
msg27918 - (view) Author: John J Lee (jjlee) Date: 2006-08-19 01:54
Logged In: YES 
user_id=261020

Patch 1459963 (applied in 50842) should be reverted and a
better patch applied (see below), since this one needlessly
breaks the old (albeit undocumented) interface of direct
access to request.headers (which existed prior to the
introduction of the .get_header() &c. methods).

Patch 1542948 reverts 50842's changes to urllib2 (it does
not revert the changes to urllib) and fixes the reported
issue with a one-line fix in AbstractHTTPHandler
(.title()-case the HTTP headers before sending them to
httplib). That fix is also more localised to HTTP -- urllib2
knows about other protocols too. This patch also corrects a
mis-wording in Misc/NEWS: the old case convention was not
strictly incorrect (according to RFC 2616), but just did not
follow the usual title-case convention.

If the original patch was applied to the 2.4 maintenance
branch, I guess patch 1542948 should be applied there too.

(Just BTW: With hindsight, the methods should never have
been introduced (which was done when the "unredirected"
headers were introduced), but rather request.headers changed
to be a class != dict: that was my fault, and it's too late
to fix that...)
History
Date User Action Args
2022-04-11 14:56:16adminsetgithub: 43105
2006-03-28 12:02:54vimicocreate