Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   httplib\urllib attributes problem (http://www.velocityreviews.com/forums/t319936-httplib-urllib-attributes-problem.html)

Bobbie 07-20-2003 07:28 PM

httplib\urllib attributes problem
 
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.

Bobbie 07-20-2003 09:28 PM

Re: httplib\urllib attributes problem
 
thanks.
question: why can't I just totally erase that "self.addheaders = " line ?

B.

----- Original Message -----
From: "Jordan Krushen" <jordan@krushen.com>
Newsgroups: comp.lang.python
To: <python-list@python.org>
Sent: Monday, July 21, 2003 9:48 AM
Subject: Re: httplib\urllib attributes problem


> On Mon, 21 Jul 2003 07:45:19 GMT, Jordan Krushen <jordan@krushen.com>
> wrote:
>
> > 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>




Jordan Krushen 07-21-2003 07:45 AM

Re: httplib\urllib attributes problem
 
On Sun, 20 Jul 2003 21:28:54 +0200, Bobbie <lorenb2@bezeqint.net> wrote:

> 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.


All times are GMT. The time now is 03:55 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.