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 user-agent header added by an opener is "frozen"
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: BreamoreBoy, ajaksu2, der_doener, orsenthil
Priority: normal Keywords: patch

Created on 2006-11-13 02:27 by der_doener, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
header-bug.txt der_doener, 2006-11-13 02:27 Sample output showing the problem
Messages (5)
msg30531 - (view) Author: Björn Steinbrink (der_doener) Date: 2006-11-13 02:27
If a Request object gets an User-agent header added by
an  opener, that header seems to be "frozen". Although
header_items() shows the changed header, the request
still uses the old one. This does not happen if the
header is set before the request is passed to the
opener, i.e. when the header is not set automatically,
subsequent changes are respected.

I'm using Python 2.4.4 from Debian's sid.
msg86315 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-04-22 18:49
Confirmed in trunk.

Easier to copy and paste:

import urllib2
h = urllib2.HTTPHandler(debuglevel = 1)
opener = urllib2.build_opener(h)

request = urllib2.Request('http://www.google.de/')
request.header_items()

opener.open(request)
request.header_items()

request.add_header('User-agent', 'Buggy')
request.header_items()

opener.open(request)
msg116182 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-09-12 12:39
What is the status of this issue?
msg117126 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-09-22 06:09
This is still a valid bug.
msg117435 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-09-27 01:41
Fixed in r85025 (py3k), r85026 (release31-maint) and r85027 (release27-maint).
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44227
2010-09-27 01:41:28orsenthilsetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg117435

stage: needs patch -> resolved
2010-09-22 06:09:41orsenthilsetassignee: orsenthil
resolution: accepted
messages: + msg117126
stage: test needed -> needs patch
2010-09-12 12:39:51BreamoreBoysetnosy: + BreamoreBoy
title: User-agent header added by an opener is "frozen" -> Urllib2 user-agent header added by an opener is "frozen"
messages: + msg116182

versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-04-22 18:49:25ajaksu2setkeywords: + patch
nosy: + ajaksu2
messages: + msg86315

2009-02-12 17:38:22ajaksu2setnosy: + orsenthil
stage: test needed
type: behavior
components: + Library (Lib), - None
versions: + Python 2.6, - Python 2.4
2006-11-13 02:27:55der_doenercreate