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

Hi PerlMonks,

I'm trying to get a page that I know have blocked my IP, so I know I will get an error, a read timeout error. This is my code:
#!/usr/bin/perl use WWW::Mechanize; my $alias = 'Linux Mozilla'; our $mech = WWW::Mechanize->new(agent => $alias); $mech->stack_depth(0); $mech->timeout(10); my $url = "http://www.nonexistent.com"; if ($mech->get($url)){ print 'OK'.$/; } else { print 'ERROR'.$/; }

I've also tryed this:
#!/usr/bin/perl use WWW::Mechanize; my $alias = 'Linux Mozilla'; our $mech = WWW::Mechanize->new(agent => $alias); $mech->stack_depth(0); $mech->timeout(10); my $url = "http://www.nonexistent.com"; my $response = $mech->get($url); if ($response->is_success) { print 'OK'.$/; } else { print 'ERROR'.$/; }

I need that the program throws the ERROR response, instead of that I always get Error GETing http://www.nonexistent.com: read timeout at ./test.pl line 13, this closes my program so I can't continue further.

Is there any way to identify this error to act consequently and not get the program closed?

thank you

Replies are listed 'Best First'.
Re: Problem with a blocked page using WWW::Mechanize
by Anonymous Monk on Apr 19, 2012 at 15:34 UTC

    WWW::Mechanize has autocheck on by default. You can trap it with eval {} or you can turn autcheck off, so it won't die

      Thank you!!

      I turned the autocheck to 0 and I've got the ERROR response. Thank you very much!!!