Forum Moderators: coopster & phranque

Message Too Old, No Replies

using LWP::Simple through CGI

unhelpful 500

         

zwhalen

11:58 pm on Dec 13, 2005 (gmt 0)

10+ Year Member



Hello. I think this is a dumb question, or at least I hope it is so someone can set me straight.

I'm trying to get a very simple Perl CGI script working that uses LWP::Simple. There are various examples of what I want to do around the web, but they all pretty much boil down to this:


use LWP::Simple;
print "Content-type: text/html\n\n";
getprint ('http://myothersite.com');
print "Hello\n";
exit;

This works fine from a shell, but returns a 500 in a browser. Normally, this would have something to do with the content type, but the 'use LWP::Simple' line seems to be the one triggering the error. That is, when that line is commented out, the script runs fine (minus retrieving the URL, of course).

Any ideas?

Many thanks.

bunltd

12:11 am on Dec 14, 2005 (gmt 0)

10+ Year Member



zwhalen, welcome to WebmasterWorld.

You don't mention it, but does your script have the shebang line in it? This is the line that starts your script file and looks like this:

#!/usr/bin/perl

That should contain the location to perl on your system.

Other things to check: your apache log file may give you some insight to the error. Also check the permissions on the file, is it 755?

Hope that helps.

LisaB

bennymack

12:23 am on Dec 14, 2005 (gmt 0)

10+ Year Member



It sounds like LWP::Simple is available to you when you run it from the command line but not to your server's CGI environment.

Definitely check your error_log. That should have the info you need to get started fixing it.

zwhalen

12:43 am on Dec 14, 2005 (gmt 0)

10+ Year Member



Hi. Thanks for the suggestions. Permissions and shebang are all okay.

I don't think I have access to the raw logs. Is it possible to specify STDERR to output to a file, or would that even be the information I need?

bennymack

1:49 am on Dec 14, 2005 (gmt 0)

10+ Year Member



Try adding this:
use CGI::Carp 'fatalsToBrowser';
until you get it debugged.

zwhalen

2:39 am on Dec 14, 2005 (gmt 0)

10+ Year Member



Ah yes, that helps. The error it prints is the "I can't find that .pm" error, which makes sense because it doesn't actually appear to be there.

What I don't understand, then, is why running the script from command line not only fails to throw out the "can't find it" error, but it also actually executes what it needs to. Does a script invoked from a browser get a different @INC than otherwise?

Edit: Benny, I just realized you already mentioned checking to see what's available in the CGI environment, so I guess the answer to my question is, "yes", and that's what I need to do about it.

Thanks.

zwhalen

3:10 am on Dec 14, 2005 (gmt 0)

10+ Year Member



That was indeed the right track. All better now.

Thanks everyone,
Zach