Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: WWW::Mechanize - Could not connect to a server

by Preceptor (Chaplain)
on Mar 20, 2007 at 11:44 UTC ( #605659=note: print w/ replies, xml ) Need Help??


in reply to WWW::Mechanize - Could not connect to a server

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(+);


Comment on Re: WWW::Mechanize - Could not connect to a server
Select or Download Code
Replies are listed 'Best First'.
Re^2: WWW::Mechanize - Could not connect to a server
by jesuashok (Curate) on Mar 21, 2007 at 02:09 UTC
    monks,

    #!/usr/bin/perl -w use WWW::Mechanize; use strict; use Data::Dumper; use Storable; my $url = 'http://www.census.gov/population/www/documentation/twps +0027.html'; my $m = WWW::Mechanize->new(); $m->http_proxy ( "proxy_address:proxy_port" );
    I tried the above code and got the error as follows :-
    Can't locate object method "http_proxy" via package "WWW::Mechanize" a +t l.pl lin e 11.
    Is there something wrong in the above Code. If so, could you add your valuable points.



    hmmm ....let me think what did I said
      If you had read the Documentation (which was pointed out to you by chargrill in the first reply to this thread) you would see that you have $m->http_proxy rather than $m->proxy. Again, if you are not sure about something why not read the documentation, it does not take that long does it?

      As a side note you can also use can to find out if a Method exists within an invocant:
      #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); if ($mech->can("http_proxy")){ print "Mech can http_proxy\n"; }else{ print "Mech can't http_proxy\n"; } if ($mech->can("proxy")){ print "Mech can proxy\n"; }else{ print "Mech can't proxy\n"; }

      Hope this helps

      Martin
        To be fair, I also hadn't done an RTFM before posting, which is why I commented on the error. Then again, I'm not the one having problems with my code :)
      There is no method http_proxy. If you RTFM you can discover the correct method.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-08-28 02:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (334 votes), past polls