Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Crashing WWW:Mech test script if page not found

by talexb (Canon)
on Jan 02, 2009 at 21:55 UTC ( #733837=perlquestion: print w/ replies, xml ) Need Help??
talexb has asked for the wisdom of the Perl Monks concerning the following question:

After writing my latest meditation I went back to searching for some answers and eventually found out that running my test script on Ubuntu was working fine, as I thought it was, but running the same test script on Solaris (targeting the same web server, of course) was breaking. Assuming that there aren't any problems with the different platforms, I had a look at the versions of the modules that might have something to do with the difference.

UbuntuSolaris
abeamish@foobar:~/dev$ dpkg -l | grep www ii libwww-perl 5.808-1 WWW client/server library for Perl (aka LWP) ii libwww-mechanize-perl 1.34-1 Automate interaction with websites
-bash-3.00$ dpkg -l | grep www ii libwww-perl 5.821-1 WWW client/server library for Perl (aka LWP) ii perl-www-mechanize 1.52-0 Perl module for handy web browsing in a Perl object

So then I went through the change deltas for WWW::Mech and LWP but didn't find anything that suggested that the strategy for GETting has changed. The error I'm getting is

Error GETing https://foo.bar/page.html: Not Found at 05_login.t line 3 +09

I don't want a 404 error to be a fatal error. If anyone can shed some light on this problem, I'd appreciate it. Thanks.

Update Well, I've got things under control for now by kludging together a SKIP block that checks $^O to see if we're running on Solaris .. except that SKIP seems to do a next and breaks out of the loop I'm currently in, and I don't want to do that. More work is required.

Update 2 Cool -- the anonymous monk (three of them, in fact) have wised me up to the autocheck argument. I'll try this out on Monday.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Comment on Crashing WWW:Mech test script if page not found
Select or Download Code
Re: Crashing WWW:Mech test script if page not found
by Anonymous Monk on Jan 02, 2009 at 22:40 UTC
    Turn off autocheck
      1.49_01 Sat Sep 27 23:50:04 CDT 2008 ======================================== [THINGS THAT MAY BREAK YOUR CODE] The autocheck argument to the constructor is now ON by default, unless WWW::Mechanize is being subclassed. There are so many new programmers whose ->get() calls fail unchecked that I'm now putting on the seat belts for them.
Re: Crashing WWW:Mech test script if page not found
by Anonymous Monk on Jan 02, 2009 at 22:40 UTC
    warn/die are not crash
Re: Crashing WWW:Mech test script if page not found
by tomfahle (Priest) on Jan 03, 2009 at 11:38 UTC

    As mentioned by others before, turn off autocheck.

    #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $browser = WWW::Mechanize->new( stack_depth => 0, # Turn off memory consuming history timeout => 180, # Set timeout in seconds autocheck => 0, # Turn off autocheck, check errors m +anually ); $browser->agent_alias( 'Windows IE 6' ); my $url = 'https://foo.bar/page.html'; $browser->get($url); if ( $browser->success( ) ) { print "Okay: $url. ", $browser->response->status_line(), "\n"; } else { print "Error: $url. Reason: ", $browser->response->status_line(), +"\n"; }

    Run the script with autocheck turned on (1) to reproduce your errormessage.

    Hope this helps.
    Thomas

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://733837]
Approved by kyle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-08-20 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls