urllib2 User-Agent annoyance

So is it just me or does Python's urllib2 distinctly not allow you to set your own User-Agent header? It specifically keeps the default User-Agent header in a separate sequence, then outputs that sequence first. If you gave your own User-Agent header, oh, well, the server gets two. Hope you don't mind that Apache only looks at the first one.

Of course, it's been fixed--just not in the version of Python I'm running. I hope they hurry with 2.3, because I don't want to upgrade first.

Actually I did try to upgrade from 2.2c1 to 2.2.2 or some odd, but according to the version it outputs when you start the shell, it's still 2.2c1. And I'm not sure to what version that patch refers, as it doesn't say; just "2.2.x," which could mean in preparation for 2.3 as far as I know, so maybe that upgrade to 2.2.2 wouldn't have helped anyhow.

Comments

comment

I found a way around the problem in 2.2 (the version of Python my hosting services provider is running). My solution is at:

http://stephen.infiniterecursion.ca/python.php

It involved puzzling over the source for urllib2… it’s bloody annoying, but once you have it, it’s not hard.