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

Greets Monks,
I have a weird error for which I think there must be a simple explanation and fix, but I can't think of it.
I'm using the Geo::Coder::Google module, and it runs fine from the command line. I've cut it down to bare bones, but when I try to run it by accessing it via a browser, it reports:
Google Maps API returned error: 500 Can't connect to maps.google.com:80 (Bad hostname 'maps.google.com') at /var/www/cgi-bin/test.cgi line 9
(you'll need to enter your own API key to work it)
#!/usr/bin/perl -T use Geo::Coder::Google; use CGI::Carp qw (fatalsToBrowser); use Data::Dumper; my $ua = LWP::UserAgent->new(agent => "Geo::Coder::Google/0.01"); my $APIKEY='Google_key_for_my_server_ip_addr'; my $geocoder = Geo::Coder::Google->new(apikey => $APIKEY ,ua => $ua) +; my $location = $geocoder->geocode( location => 'Hollywood and Highla +nd, Los Angeles, CA' ); print Dumper($location);
Any ideas?

Replies are listed 'Best First'.
Re: Geo::Coder::Google running as cgi
by Anonymous Monk on Sep 14, 2008 at 09:59 UTC
    500 Can't connect to maps.google.com:80 (Bad hostname 'maps.google.com')
    That means DNS (your computer) can't resolve maps.google.com into an IP address. Could be because of firewall, permissions or just because :)
      thats what I thought initially, but being that it runs fine from the command line, wouldn't that indicate that it can be resolved. The only thing I can think of is some sort of apache.conf issue
        The webserver (apache/httpd) runs as some user (ex apache) which is not the same user (you) in the shell, so permissions can be different, %ENV ....
Re: Geo::Coder::Google running as cgi
by oko1 (Deacon) on Sep 14, 2008 at 23:18 UTC

    When in doubt, strip the problem part to the bone. Since it seems that DNS is the likely culprit, try something simple that checks DNS and involves a minimum of other code:

    #!/bin/bash host=$(/usr/bin/host maps.google.com) cat <<! Content-Type: text/plain $host !

    If you run the above as CGI and see a reasonable output for host - e.g.,

    maps.google.com is an alias for maps.l.google.com. maps.l.google.com has address 64.233.161.147 maps.l.google.com has address 64.233.161.99 maps.l.google.com has address 64.233.161.104

    - then your server/browser combo is handling resolution just fine. Otherwise, you'll need to dig (erm, pun only semi-intentional :) elsewhere.

    
    -- 
    Human history becomes more and more a race between education and catastrophe. -- HG Wells
    
Re: Geo::Coder::Google running as cgi
by ikegami (Patriarch) on Sep 14, 2008 at 23:32 UTC
    Sounds like the problems encountered by the security limitations of SElinux. Is that what you are using?
      or AppArmor if he uses Suse