views:

311

answers:

3

This script:

use strict;
use warnings;
use WWW::Mechanize;

my $mech = WWW::Mechanize->new( autocheck => 1 );

$mech->get( "http://www.google.com" );
print $mech->content;

Produces this error message:

Error GETing http://www.google.com: Can't connect to www.google.com:80 (connect: Unknown error) at D:\PERL\try.pl line 5

What's wrong?

+2  A: 

Did it work before? This code works on my Linux box.

  1. It could be that you have no internet connection.
  2. Maybe Google blocked you.
Peter Stuifzand
no i have internet connection and am getting this error for all the sites.... even if i try to open a html file in my system it throws me the same error.
lokesh
+6  A: 

From your error message I see that you're on a Windows box (D:\PERL\try.pl). Maybe the Windows firewall doesn't trust Perl to access the internet and blocks its traffic?

You might get lucky adding a rule allowing perl.exe access to the internet in the Windows firewall.

Olfan
+1  A: 

Might be your firewall like Olfan said or you might need to have to use a proxy in your environment.

innaM
can u tell me how can i use the proxy please..in my code.. also how can i set my firewall settings in order to work my code
lokesh
Please referr to the LWP::UserAgent documentation for information regarding the proxy: http://search.cpan.org/perldoc?LWP::UserAgentSince I don't know the first thing about Windows (let alone what personal firewall you are using), I can't help you with the firewall.
innaM