urllib2 / ClientCookie / Keep-Alive

Discussion in 'Python' started by Richie Hindle, Oct 15, 2004.

  1. Hi,

    I'm trying to write a test script to hammer an HTTP server over a
    persistent HTTP 1.1 connection. The server uses cookies, so I'm using a
    combination of ClientCookie 0.4.19 and urllib2 with Python 2.3.4 on
    Windows XP. This is what I have so far:

    import urllib2, ClientCookie
    UA = 'Mozilla/4.0 (compatible; MSIE 6.0;)'
    URL = 'http://server/resource/'
    opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor)
    while 1:
    request = ClientCookie.Request(URL)
    request.add_header('User-Agent', UA)
    print repr(opener.open(request).read()[:100])

    Which works fine, but opens a new connection for every request.
    Following some (dubious) code I found with Google, I added this:

    request.add_header('Connection', 'Keep-alive')

    but that makes it hang.

    Can someone tell me the official way to enable urllib2 and/ClientCookie
    to use persistent connections?

    (I briefly tried Python 2.4, but that didn't work either. If there's
    solution that requires Python 2.4, that's no problem.)

    --
    Richie Hindle
     
    Richie Hindle, Oct 15, 2004
    #1
    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. Luiz Alberto Gibson da Costa

    web chat development, http header connection: keep-alive

    Luiz Alberto Gibson da Costa, Aug 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    635
    Luiz Alberto Gibson da Costa
    Aug 6, 2003
  2. Grant Edwards

    Why is ClientCookie/urllib2 using https?

    Grant Edwards, Sep 24, 2003, in forum: Python
    Replies:
    0
    Views:
    354
    Grant Edwards
    Sep 24, 2003
  3. Chuck Bearden
    Replies:
    2
    Views:
    806
    Chuck Bearden
    May 11, 2004
  4. David Rasmussen

    HTTP Keep-Alive with urllib2

    David Rasmussen, Nov 14, 2005, in forum: Python
    Replies:
    1
    Views:
    1,094
    Steve Holden
    Nov 16, 2005
  5. hisan
    Replies:
    1
    Views:
    1,423
    Dan Stromberg
    Jun 25, 2012
Loading...

Share This Page