in reply to Re: Google Images via CGI
in thread Google Images via CGI

My code is spiked with print statements after nearly every line, but I figured you wouldn't want to read them. $google is defined, $key is copied from the other program (which works) and is exactly identical, and $hashref1 never happens. The error message I get is

 request to http://ajax.googleapis.com/ajax/services/search/images?hl=ja&rsz=small&q=%E4%BA%BA&v=0.1&api_key=[my key]&start=0 failed at [my program] line 59

for line 59 being

my $hashref1 = $google->get( {v => "0.1", q => "$query", rsz => "small", hl => "ja", start => "$i"} )

I get this error message after some two minutes or so of nothing happening, which is exactly how my programs reacted before to a forgotten proxy. That is why I assumed it was a firewall problem, again.

%ENV is indeed very different - none of the keys seem to be the same. I don't know how that helps me, though. Please explain?

Replies are listed 'Best First'.
Re^3: Google Images via CGI
by Anonymous Monk on Sep 03, 2009 at 08:43 UTC
    That error message sucks because it doesn't say why it failed. Try turn on debug option, maybe you will get better message.

      Outing myself as a total novice: How do I debug a cgi? Beyond checking beforehand with perl -wc my_program.pl and sending any errors to a file with use CGI::Carp qw(carpout);, what options do I have? Is there a way to run a cgi with -d in the shell, even though the cgi needs user input to get to the problematic lines of code?

        Since WebService::Simple->isa('LWP::UserAgent') you can use
        $google->add_handler("request_send", sub { shift->dump; return }); $google->add_handler("response_done", sub { shift->dump; return });
        I was going to suggest you use the WebService::Simple->new( debug => 1 ...) option, but it wouldn't have helped. I would switch to WWW::Mechanize (or WWW::Mechanize::Cached), its much better in all respects.
Re^3: Google Images via CGI
by Sewi (Friar) on Sep 03, 2009 at 12:23 UTC
    Very often a
    print Dumper($google)."\n";
    helps. It usually contains the request and the reply.

    Not a Perl solution, but when debugging SOAP-crap very often

    tcpdump -nXs 8192 -c 1000 port 80 >dump.log
    also helps alot, because you get the raw data stream. You man need to be more specific with the filter conditions depending on the load of your computer.
      Not WebService::Simple , its special like that :)