[issue2756] urllib2 add_header fails with existing unredirected_header

Martin McNickle report at bugs.python.org
Mon May 5 11:45:11 CEST 2008


Martin McNickle <mmcnickle at gmail.com> added the comment:

I can see that there will be a problem in this case.

However, it may be that the authors found it more intuitive to always
set the Content-Type to application/x-www-form-urlencoded when data is set.

Their implementation is inconsistent though:

#-------------------------------------------------------
request = urllib2.Request('http://www.somesite.com/')
request.add_data(data)
f = urllib2.urlopen(request)

# 'Content-Type: application/x-www-form-urlencoded' is sent in the header
#-------------------------------------------------------

whereas:

#-------------------------------------------------------
request = urllib2.Request('http://www.somesite.com/')
request.add_header('Content-Type', 'application/xml')
request.add_data(data)

# 'Content-Type: application/xml' is sent in the header
#-------------------------------------------------------

We need to decide what is the best way to handle this case.  Should the
normal headers be given preference, or should the unredirected headers
be given preference?

--- Martin

----------
nosy: +BitTorment

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2756>
__________________________________


More information about the Python-bugs-list mailing list