urllib - changing the user agent

John J. Lee jjl at pobox.com
Sat Jan 10 12:44:16 EST 2004


Samuel Walters <swalters_usenet at yahoo.com> writes:

> |Thus Spake John J. Lee On the now historical date of Fri, 09 Jan 2004
> 20:16:54 +0000|
>  
> > or again, you can set .addheaders on OpenerDirector (which will cause
> > those headers to be added to all requests).

(just to clarify, I meant an OpenerDirector instance, not the class
itself)


> This, however, does not stop the original User-agent header to be sent,
> and google still filters out the request.  Instead, it just causes a
> second user-agent to be sent.

No, it does stop them being sent.  Perhaps you mutated the base class
.addheaders by mistake (using .append(("User-agent", "blah")), for
example)?  Don't do that!  Mutating class attributes is a bad idea.


> Here is the very bad code I used to solve this problem.  There are better
> ways, I assure you, but it should point you in the right direction.  You
[...]

No need to assure me of *that* <wink>.  You can call a base class
constructor directly, you know.  And clobbering the base class'
constructor is another very bad idea.


John



More information about the Python-list mailing list