httplib\urllib attributes problem

Discussion in 'Python' started by Bobbie, Jul 20, 2003.

  1. Bobbie

    Bobbie Guest

    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, Jul 20, 2003
    #1
    1. Advertising

  2. Bobbie

    Bobbie Guest

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

    B.

    ----- Original Message -----
    From: "Jordan Krushen" <>
    Newsgroups: comp.lang.python
    To: <>
    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 <>
    > 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
    >
    Bobbie, Jul 20, 2003
    #2
    1. Advertising

  3. On Sun, 20 Jul 2003 21:28:54 +0200, Bobbie <> 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.
    Jordan Krushen, Jul 21, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hitectahir
    Replies:
    0
    Views:
    351
    hitectahir
    Jul 1, 2003
  2. deelan
    Replies:
    0
    Views:
    1,235
    deelan
    Apr 1, 2004
  3. Terry Kerr

    httplib.HTTPSConnection problem

    Terry Kerr, Jul 16, 2004, in forum: Python
    Replies:
    0
    Views:
    789
    Terry Kerr
    Jul 16, 2004
  4. Jonathan Gardner

    Asynchronous urllib (urllib+asyncore)?

    Jonathan Gardner, Feb 26, 2008, in forum: Python
    Replies:
    1
    Views:
    459
    Terry Jones
    Feb 27, 2008
  5. Chris McDonald
    Replies:
    0
    Views:
    272
    Chris McDonald
    Nov 1, 2010
Loading...

Share This Page