Python equivalent of LWP and HTTP in Perl

Irmen de Jong irmen at -nospam-remove-this-xs4all.nl
Thu Oct 28 21:54:44 CEST 2004


Dekaritae wrote:
> 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).

>   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;


import urllib
proxies = {'http': 'http://localhost:8080/'}
response = urllib.urlopen("some_url", proxies=proxies).read()

--Irmen



More information about the Python-list mailing list