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

Dear Monks,
I am trying to run following simple code from my machine
use strict; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get("http://www.google.com"); print $mech->content();
I am getting following error page in return (Surprisingly when I go to www.google.com through Mozilla or IE it allows me to go to it.) Any idea what has gone wrong?

The error is follows.
=======================
<H1>ERROR</H1> <H2>Cache Access Denied</H2> <HR noshade size="1px"> <P> While trying to retrieve the URL: <A HREF="http://www.google.com">http://www.google.com</A> <P> The following error was encountered: <UL> <LI> <STRONG> Cache Access Denied. </STRONG> </UL> </P> <P>Sorry, you are not currently allowed to request: <PRE> http://www.google.com</PRE> from this cache until you have authenticated yourself. </P> <P> You need to use Netscape version 2.0 or greater, or Microsoft Internet Explorer 3.0, or an HTTP/1.1 compliant browser for this to work. Plea +se contact the <A HREF="mailto:root">cache administrator</a> if you have difficulties authenticating yourself or <A HREF="http://squid.YOURDOMAINHERE.com/cgi-bin/chpasswd.cgi">change< +/a> your default password. </P> <BR clear="all"> <HR noshade size="1px">

20060505 Janitored by Corion: Moved error message HTML into code tags

Replies are listed 'Best First'.
Re: Mechanize module
by bart (Canon) on May 05, 2006 at 12:44 UTC
    You have to pass in proxy credentials to the UA. Most likely, Mozilla and MSIE are set up to do it properly by themselves.

    Since WWW::Mechanize ISA LWP::UserAgent, you can use the methods as described in lwpcook, to achieve that goal.

Re: Mechanize module
by Corion (Patriarch) on May 05, 2006 at 12:09 UTC

    Please read the error message you get back:

    • Cache Access Denied.

    Sorry, you are not currently allowed to request:

    http://www.google.com

    from this cache until you have authenticated yourself.

    So, you will need to authenticate yourself before you can access the page.

Re: Mechanize module
by gellyfish (Monsignor) on May 05, 2006 at 12:18 UTC

    This message is coming from an intervening caching proxy, you probably need to authenticate to the proxy.

    /J\

Re: Mechanize module
by ahmad (Hermit) on May 05, 2006 at 19:04 UTC

    i think you need to set the "Agent alias" using

    $mech->agent_alias( 'Windows IE 6' );

    so your request will appear as its comming from Internet Explorer