Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > httplib\urllib attributes problem

Reply
Thread Tools

httplib\urllib attributes problem

 
 
Bobbie
Guest
Posts: n/a
 
      07-20-2003
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.
 
Reply With Quote
 
 
 
 
Bobbie
Guest
Posts: n/a
 
      07-20-2003
thanks.
question: why can't I just totally erase that "self.addheaders = " line ?

B.

----- Original Message -----
From: "Jordan Krushen" <(E-Mail Removed)>
Newsgroups: comp.lang.python
To: <(E-Mail Removed)>
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 <(E-Mail Removed)>
> 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
>



 
Reply With Quote
 
 
 
 
Jordan Krushen
Guest
Posts: n/a
 
      07-21-2003
On Sun, 20 Jul 2003 21:28:54 +0200, Bobbie <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
data attributes override method attributes? Jayden Python 16 09-29-2012 03:20 AM
attributes ala java annotations or .Net attributes? Kyle Schmitt Ruby 3 07-24-2007 07:48 PM
class attributes & data attributes james_027 Python 2 06-20-2007 03:12 PM
WebControl.Attributes.Add and custom attributes P4trykx ASP .Net 2 01-31-2007 04:33 PM
Parse reserved attributes as normal attributes Max XML 1 09-22-2006 12:04 PM



Advertisments