httplib\urllib attributes problem

B

Bobbie

hello ppl,

While trying to build a web client I've encountered problems using both
httplib and urllib2.

The problem with httplib is that the "Accept-Encoding: Identity" HTTP header is
always sent by the library with no regard to my headers configuration. in case
I setup an "Accept-Encoding" header of my own it just sends them both...

The problem with urllib2 is that a "User-agent: Python-urllib/2.0a1" is, again, sent
by default. in case I setup a "User-Agent" attribute of my own it just, again, sends
them both. Note the lower-case 'a' letter in the former user-agent
automatically sent by the library. I can't even overrun it because of that.

I'll be happy for any kind of help, suggestion,...

thanks

Bob.
 
B

Bobbie

thanks.
question: why can't I just totally erase that "self.addheaders = " line ?

B.

----- Original Message -----
From: "Jordan Krushen" <[email protected]>
Newsgroups: comp.lang.python
To: <[email protected]>
Sent: Monday, July 21, 2003 9:48 AM
Subject: Re: httplib\urllib attributes problem

At least for this one, here's the relevant code from urllib2.py:

class OpenerDirector:
def __init__(self):
server_version = "Python-urllib/%s" % __version__
self.addheaders = [('User-agent', server_version)]

You should be able to override your opener's addheaders attribute
(untested):

opener.addheaders = None

Actually, it's late. Use this instead:

opener.addheaders = []

This won't break if something else tries to append to the list.

J.
 
J

Jordan Krushen

The problem with urllib2 is that a "User-agent: Python-urllib/2.0a1" is,
again, sent
by default. in case I setup a "User-Agent" attribute of my own it just,
again, sends
them both. Note the lower-case 'a' letter in the former user-agent
automatically sent by the library. I can't even overrun it because of
that.

I'll be happy for any kind of help, suggestion,...

At least for this one, here's the relevant code from urllib2.py:

class OpenerDirector:
def __init__(self):
server_version = "Python-urllib/%s" % __version__
self.addheaders = [('User-agent', server_version)]

You should be able to override your opener's addheaders attribute
(untested):

opener.addheaders = None

J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top