473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

urllib2 / ClientCookie / Keep-Alive

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.HTTPCookieP rocessor)
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
ri****@entrian.com

Jul 18 '05 #1
0 1760

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Grant Edwards | last post by:
In the program shown below, all of the connections to the servers are using port 443 and https (TLS protocol) -- both the initial connection to login.postini.com and subsequent connections to...
5
by: Rafael T. Ugolini | last post by:
Im trying to add more than one cookie with urllib2 but im not getting much sucess. An example... >>> req = urllib2.Request('http://localhost','j_username=psyca&j_password=******',{...
1
by: Doug Gray | last post by:
Python2.3 on Redhat Linux 8.0 here is the code. import urllib2 import ClientCookie request = urllib2.Request("http://fantasygames.sportingnews.com/crs/home_check_reg.htm
2
by: Richard Shea | last post by:
Hi - I'm writing a script which fetches a page from a web server and takes note of any set-cookies which are served in the headers so that when I next request a page I can send those cookies back...
1
by: Doug Farrell | last post by:
Hi all, I'm trying to build a web page crawler to help us build our websites, which are driven by static pages after they are called the first time. Anyway, I can use urllib2.urlopen() no...
1
by: Erling Ringen Elvsrud | last post by:
Hello, My aim is to write a small application to use free sms-sending services in a more convenient way than with a web-browser. I found: http://wwwsearch.sourceforge.net/mechanize/ (which...
3
by: Michael Foord | last post by:
Does anyone know how to do a 'file upload' using urllib2 ? There is an example of doing file upload using httplib - on activestate python cookbook. I have code that uses a request object to make...
3
by: Artificial Life | last post by:
urllib2 does not seem to be able to handle META-REFRESH in an html document. I just get back the html to the page that is supposed to forward me to the intended page. Any way around this?
0
by: Robert | last post by:
using a proxy and https/SSL together I get the following SSL error : File "dscore.pyo", line 2257, in UrlOpenEx File "ClientCookie\_urllib2_support.pyo", line 572, in open File...
7
by: itay_k | last post by:
Hi, I dont understand why this is so complicated, just to add one line of cookie header on the GET request. This is my unworking code: import time import Cookie import cookielib, urllib2
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.