Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

WWW::Mechanize Timeout period

by gutbobs (Initiate)
on Jul 27, 2009 at 15:50 UTC ( [id://783577]=perlquestion: print w/replies, xml ) Need Help??

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

Hi All, The is the first time I've ever looked at doing anything with Perl so bear with me..

I'm developing a system that monitors around 100 proxy servers. The proxy servers have a web page on them that displays the system status and I can't get this info out of them via SNMP.

I'm trying to replace a bash script that uses lynx to browse to the appropriate page because lynx falls over if the password is wrong. I've got the following code, which works, but when one of the proxy servers is switched off the time out period is being ignored and there is a pause of nearly 4 minutes whilst the perl script sits round doing nothing. My code is below.

It's running on Ubuntu 8.04 server (kernel is 2.6.15-26) and perl is version 5.8.7. WWW::Mechanize should be the latest version

#!/usr/bin/perl use WWW::Mechanize; use MIME::Base64; use warnings; $PASSWORD=$ARGV[1]; $IPADDRESS="HTTPS://" . $ARGV[0]; print "IP Address:$ARGV[0]\n"; print "Password:$ARGV[1]\n"; my $mech=WWW::Mechanize->new( stack_depth => 0, timeout => 10, autocheck => 0, ); #$mech->agent_alias( 'Windows IE 6' ); my @args = ( Authorization => "Basic " . MIME::Base64::encode( 'manage +r' . ':' . $PASSWORD )); $mech->get( $IPADDRESS, @args ); if ( $mech->success( ) ) { print "OK:",$mech->response->status_line(),"\n"; $EXIT_CODE=0; } else { print "Fail:",$mech->response->status_line(),"\n"; $EXIT_CODE=1; } #print $mech->content(); print "Exiting with exit code:$EXIT_CODE\n"; exit($EXIT_CODE)
Am I missing something obvious? I've done various searches and can't see what might be wrong

Cheers

Rich

Replies are listed 'Best First'.
Re: WWW::Mechanize Timeout period
by jrsimmon (Hermit) on Jul 27, 2009 at 16:05 UTC

    Looks like mech doesn't do anything special with the timeout, so you're just dealing with LWP::UserAgent. The first thing I'd check is whether you're actually getting the timeout set with your code. From the LWP doc:

    $ua->timeout $ua->timeout( $secs ) Get/set the timeout value in seconds. The default timeout() value is 1 +80 seconds, i.e. 3 minutes.

      I've successfully tested that the timeout option used in WWW::Mechanize::new works as expected for me.

      DB<1> use WWW::Mechanize DB<2> $mech = WWW::Mechanize->new (timeout=>300) DB<3> x $mech->get ('http://192.168.1.77') Error GETing http://192.168.1.77: Can't connect to 192.168.1.77:80 (co +nnect: No route to host) at (eval 35)[/usr/share/perl/5.10/perl5db.pl +:638] line 2 DB<4> x $mech->timeout 0 300 DB<5> x $mech->timeout(1) 0 300 DB<6> x $mech->timeout 0 1 DB<7> x $mech->get ('http://192.168.1.77') Error GETing http://192.168.1.77: Can't connect to 192.168.1.77:80 (co +nnect: timeout) at (eval 40)[/usr/share/perl/5.10/perl5db.pl:638] lin +e 2

      Note the difference in error message reported.

Re: WWW::Mechanize Timeout period
by Anonymous Monk on Jul 27, 2009 at 16:03 UTC
Re: WWW::Mechanize Timeout period
by alexm (Chaplain) on Jul 27, 2009 at 23:01 UTC

    Am I missing something obvious?

    Which error is reported after those 4 minutes? Is it the same error if you use an unused IP address? And for an existing IP address but without a web server listening there?

    FWIW, I performed the tests on mech version 1.52.

      Thanks All.


      In response to Alexm.

      For a switched off device:

      Error Code:Error GETing HTTPS://10.241.65.134: Can't connect to 10.241.65.134:443 (connect: Connection timed out) at test5.pl line 24

      For a machine that doesn't have a web server:

      Error Code:Error GETing HTTPS://10.241.3.11: Can't connect to 10.241.3.11:443 (connect: Connection refused) at test5.pl line 24

      However....

      I've just noticed that the timeout works when using port 80 instead of port 443. This might be enough for me to get around my problem (if I can get a response from port 80 then I can go for port 443).

      Thanks again

      Rich

        I confirm that the timeout doesn't work as expected when using https. The port is not significant, since I tried port 443 with http and timeout worked fine.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2025-03-18 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (56 votes). Check out past polls.