jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

monks,

This is the first time I am trying some sample programs using WWW::Mechanize. I got this sample code from here

#!/usr/bin/perl -w use WWW::Mechanize; use Data::Dumper; use Storable; $url = 'http://www.census.gov/population/www/documentation/twps002 +7.html'; $m = WWW::Mechanize->new(); $m->get($url); $c = $m->content; print Dumper [ $c ];
I got the below Error :-
$VAR1 = [ '500 Can\'t connect to www.census.gov:80 (connect: Unknown e +rror) ' ];
But I could connect to the URL via web browser. Could anyone help me to resolve this issue ?



hmmm ....let me think what did I said

Replies are listed 'Best First'.
Re: WWW::Mechanize - Could not connect to a server
by chargrill (Parson) on Mar 20, 2007 at 03:20 UTC

    Are you behind a proxy?

    If you are, WWW::Mechanize respects your $ENV{HTTP_PROXY} environment variable - you could try setting that in your program to whatever your browser is set to.

    Update: Just checked the Mech FAQ, How to use mech through a proxy might be of interest, too



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: WWW::Mechanize - Could not connect to a server
by Preceptor (Deacon) on Mar 20, 2007 at 11:44 UTC
    You've mentioned you're using a proxy.

    You need to set up WWW:Mechanize to use your proxy. Ideally, you'll use the in-built OS options, but as a shortcut (to check if this actually is your problem) then just use:

    my $mech = WWW::Mechanize -> new(); $mech -> http_proxy ( "Your_proxy_address:proxy_port" )
    I've also found enabling LWP debugging to be most useful when troubleshooting Mechanized scripts.
    use LWP::Debug qw(+);
    A reply falls below the community's threshold of quality. You may see it by logging in.