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

running cgi off the command line works, but running on the browser fails with a 500 error

by pat_rice_irl (Initiate)
on Sep 27, 2007 at 16:11 UTC ( [id://641372]=perlquestion: print w/replies, xml ) Need Help??

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

Error 500 error is the follwoing
Thu Sep 27 16:26:56 2007 error client 10.16.153.99 Prototype mismatch: sub main::head: none vs ($) at /var/www/cgi-bin/srHandler4.cgi line 7
Thu Sep 27 16:26:57 2007 error client 10.16.153.99 Thu Sep 27 16:26:57 2007 srHandler4.cgi: Error 500 on http://pseweb.vmware.com/pending/194951021 a t /var/www/cgi-bin/srHandler4.cgi line 25.
The problem is with line 7 and 25
line 7 -- shown below is prety simple
5 #### adding the bits from teat.pl
6 use warnings;
7 use LWP::Simple;

Line 25 -- shown below, is just a simple getstore, this works when run from the command line, but when run form the webserver, I get above error message, I've tried the usual 500 error messages, just wondering if anyone has any ideas ???
21 my $url = "http://private.private.com/pending/$variable_name";
22 #print "\n This is the web site that I'm trying to got to : $url";
23 my $file = 'testPseweb2.html';
24 my $status = getstore($url, $file);
25 die "Error $status on $url" unless is_success($status);

I've been stuck on this for a while and I'm starting to wonder..... I'm attaching script below
1 #!/usr/bin/perl -w 2 use CGI qw(:standard); 3 use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 4 use strict; 5 #### adding the bits from teat.pl 6 use warnings; 7 use LWP::Simple; 8 9 ###### setting up the variables for the form 10 my $query; 11 my $p; # chaged this for trouble shooting 12 #my $variable_name = param("srNumber"); 13 my $variable_name = 194951021; 14 15 16 17 ####### adding teat.pl 18 #here I take the number form the form and try to pull down pag +e 19 # This fails with 500 error, but testing it through a browser +it works, 20 # Hence the resion for the print statment 21 my $url = "http://test.test.com/pending/$variable_name"; 22 #print "\n This is the web site that I'm trying to got to : $u +rl"; 23 my $file = 'testPseweb2.html'; 24 my $status = getstore($url, $file); 25 die "Error $status on $url" unless is_success($status); 26 27 28 29 30 31 ####### this part parses the file pulled down from lwp, and pi +ck out what I want 32 my $img; 33 my $src; 34 my $alt; 35 my $a; 36 my $href; 37 my $href2; 38 my $msup; 39 my $msupdir; 40 my $substrMsup; 41 42 43 open(IN, "<$file") || die "Can't open $file: $!"; 44 while (<IN>) { 45 my @array_of_data = <IN>; 46 47 foreach my $line (@array_of_data) 48 { 49 50 chomp($line); 51 52 if ($line =~ /vm-support/i) 53 { 54 55 ################Now do something in this if st +atment 56 ############ Split The file, and pick out t +he correct word for time and date. 57 ##I'm picking out what I want out of the web p +age here 58 ($img, $src, $alt, $a, $href) = split (' ', $l +ine); 59 ($href2, $msup, $msupdir) = split ('"', $href) +; 60 ($substrMsup) = split ('/', $msup); 61 } 62 } 63 } 64 close(IN); 65 66 print header; 67 print start_html("Thank You"); 68 print h2("Thank You"); 69 70 #print "variable name: $variable_name"; 71 #print "vm-support: $substrMsup"; 72 print end_html; 73 74 75 76
  • Comment on running cgi off the command line works, but running on the browser fails with a 500 error
  • Download Code

Replies are listed 'Best First'.
Re: running cgi off the command line works, but running on the browser fails with a 500 error
by ikegami (Patriarch) on Sep 27, 2007 at 16:21 UTC

    You would have gotten the first error from the command prompt too, unless you were using a different Perl.

    The problem is that both LWP::Simple and CGI have a method called head, and both export it to your module.

    Prevent LWP::Simple from exporting its head by replacing
    use LWP::Simple;
    with
    use LWP::Simple qw( getstore );

    Update: Oops! That only addresses the first error. I addressed the second error in a later post.

Re: running cgi off the command line works, but running on the browser fails with a 500 error
by ikegami (Patriarch) on Sep 27, 2007 at 16:32 UTC

    This only addresses the second error. I already addressed the first error in an earlier post.

    The second error means that http://pseweb.vmware.com/pending/194951021 returned status code 500, getstore is unable to fetch that resource, or some internal error occured in getstore. getstore doesn't provide much feedback, unfortunately. You could use LWP::UserAgent's request method instead of LWP::Simple's getstore and dump the response on error, but I suspect it's one of the following:

    • The currect directory isn't what you think it is. It's probably /. Use absolute paths or chdir to the desired directory.
    • LWP is unable to create the file because the user as which your script runs cannot write to the current directory. Adjust file permissions accordingly.
    • CGI script can't do HTTP requests on your server. Adjust your server's security settings and/or the settings of the proxy/firewall/router protecting in front of your server.

    The first two problems can also be avoided by not using a file at all. If you don't actually need to store the file, just use get.

    use LWP::Simple qw( get ); my $data = get($url); open(IN, '<', \$data); while (<IN>) { ...
Re: running cgi off the command line works, but running on the browser fails with a 500 error
by rdfield (Priest) on Sep 27, 2007 at 16:30 UTC
    The webserver probably can't write to location "$file". Try a full path into a directory that anyone can write to.

    rdfield

Re: running cgi off the command line works, but running on the browser fails with a 500 error
by adamk (Chaplain) on Sep 28, 2007 at 01:42 UTC
    Sounds like you aren't replicating the CGI environment on the command line properly.

    Have a look at CGI::Capture.

    It will do a really paranoid capture of the CGI call, and make sure it gets replicated to the command line properly.
Re: running cgi off the command line works, but running on the browser fails with a 500 error
by mr_mischief (Monsignor) on Sep 27, 2007 at 16:27 UTC
    perldoc -q 500 Server Error

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://641372]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found