Python equivalent of LWP and HTTP in Perl

Michael Foord fuzzyman at gmail.com
Fri Oct 29 08:54:31 EDT 2004


Dekaritae <maur at mdi.ca> wrote in message news:<vAbgd.24$SJ2.18 at fe61.usenetserver.com>...
> I have a script that I've written in Perl that retrieves files generated 
> from a template. It works decently enough, but I'd like to rewrite it in 
> Python (Perl was just a detour; it was originally Sed).
> 
> Was wondering what the closest thing to what I'm using now in Perl 
> (LWP::UserAgent and HTTP::Request:Common) is in Python. The main bit of 
> my code is fairly simple.
> 
>    my($ua) = LWP::UserAgent->new;
>    my $req = GET "$uri";
>    $req->header(Referer => "$referer");
>    $ua->proxy('http', 'http://localhost:8080/'); # Proxomitron
>    $response = $ua->request($req);
>    $respcode = $response->code;

urllib2 is definitely the way forward for adding proxy support and
request headers. Very easy. If you want cookie handling you'll need to
look at ClientCookie which does similar things to the perl library you
mention.

Regards,

Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html



More information about the Python-list mailing list