Re: Python equivalent of LWP and HTTP in Perl

From: Michael Foord (fuzzyman_at_gmail.com)
Date: 10/29/04


Date: 29 Oct 2004 05:54:31 -0700

Dekaritae <maur@mdi.ca> wrote in message news:<vAbgd.24$SJ2.18@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



Relevant Pages

  • Re: Perl + Dreamweaver?
    ... >>> In your opinion whats the easiest way of creating a Perl CGI Webpage ... DreamWeaver and CSS do three very different things. ... This is an example of template that HTML::Template needs to work. ...
    (comp.lang.perl.misc)
  • Re: Best way to handle using a report template for non-programmers..
    ... >> I would rather it be more readable to someone who does not know perl. ... define a "template" to use (which is nothing more than field ... descriptions and what pack format to use): ...
    (comp.lang.perl.misc)
  • Re: PERLs equivalent to an "include file"
    ... > I would like to include a PERL file within an html or asp file. ... Mason embeds snippets of Perl in your HTML, much like ASP or JSP does. ... HTML::Template makes this kind of isolation much simpler, ...
    (perl.beginners)
  • Re: Example of web application done right?
    ... >> We used perl, and regretted it for the web interface. ... > Template Toolkit, then I am surprised at your statement. ... mod_perl on an Apache server can do ANYTHING. ... Yes, if the cost of having extra servers do sessions is justified, it'd be ...
    (comp.lang.perl.misc)
  • Re: what is %process XX%
    ... by some sort of template processor with an actual value. ... If you can find the perl code that does the processing, ...
    (comp.lang.perl.misc)