[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby and CGI error 500

greyfade@gmail.com

5/21/2005 10:10:00 PM

this is a problem that's been driving me nuts ever since i first tried
it.

i can create simple, minimal scripts in Python, Perl, and PHP that run
flawlessly on the first try with minimal effort, both on my local
testing system (Apache 2.0.52 and Ruby 1.8.2) and on the server my
personal site is hosted on (Apache 1.3.33 and unknown version of Ruby -
i'm trying to find out). but no matter what i try, i simply can not
get even the most minimal ruby script to function:

#!/usr/bin/env ruby

print "Content-type: text/html\n\n"
print "<html><body>Hello World!</body></html>\n"

it runs perfectly fine at the console, no warnings, no errors, no
problems. but as a CGI script, it's another story: i get an error 500
and the cryptic (and seemingly common) "Premature end of script
headers". no other warnings or errors. if i simply change "ruby" to
"python" on the shebang line, the above script magically works with no
other effort on my part.

i'm going insane because nothing, AFAICT, is wrong. the server is
correctly set-up, permissions are correct, ownership is correct, ruby
is installed and working, yet NOTHING seems to coax it into working.
it repeatedly reports this incredibly uninformative "Premature end of
script headers" error.

is there something i could have missed? a possible misconfiguration?
or does ruby just hate me?

10 Answers

james_b

5/21/2005 11:27:00 PM

0

greyfade@gmail.com wrote:

Given this:

> #!/usr/bin/env ruby

What user is executing the script, and is ruby in that user's env?

Try putting the literal path to Ruby there instead.


James


Ara.T.Howard

5/22/2005 12:06:00 AM

0

ES

5/22/2005 1:16:00 AM

0


Le 21/5/2005, "greyfade@gmail.com" <greyfade@gmail.com> a écrit:
>this is a problem that's been driving me nuts ever since i first tried
>it.
>
>i can create simple, minimal scripts in Python, Perl, and PHP that run
>flawlessly on the first try with minimal effort, both on my local
>testing system (Apache 2.0.52 and Ruby 1.8.2) and on the server my
>personal site is hosted on (Apache 1.3.33 and unknown version of Ruby -
>i'm trying to find out). but no matter what i try, i simply can not
>get even the most minimal ruby script to function:
>
>#!/usr/bin/env ruby
>
>print "Content-type: text/html\n\n"
>print "<html><body>Hello World!</body></html>\n"
>
>it runs perfectly fine at the console, no warnings, no errors, no
>problems. but as a CGI script, it's another story: i get an error 500
>and the cryptic (and seemingly common) "Premature end of script
>headers". no other warnings or errors. if i simply change "ruby" to
>"python" on the shebang line, the above script magically works with no
>other effort on my part.

This, actually, goes to the HTTP spec. Try this:

#!/bin/env/ ruby
print "HTTP/1.0 200 OK\r\n"
print "Content-type: text/html\r\n\r\n"
print "<html><body>Hello World!</body></html>\n"

>i'm going insane because nothing, AFAICT, is wrong. the server is
>correctly set-up, permissions are correct, ownership is correct, ruby
>is installed and working, yet NOTHING seems to coax it into working.
>it repeatedly reports this incredibly uninformative "Premature end of
>script headers" error.
>
>is there something i could have missed? a possible misconfiguration?
>or does ruby just hate me?

E

--
template<typename duck>
void quack(duck& d) { d.quack(); }


greyfade@gmail.com

5/23/2005 7:28:00 AM

0

(apologies to ES: i hit "reply to author" entirely by accident.)

ES wrote:
> Le 21/5/2005, "greyfade@gmail.com" <greyfade@gmail.com> a écrit:
> >this is a problem that's been driving me nuts ever since i first
tried
> >it.
> >
> >i can create simple, minimal scripts in Python, Perl, and PHP that
run
> >flawlessly on the first try with minimal effort, both on my local
> >testing system (Apache 2.0.52 and Ruby 1.8.2) and on the server my
> >personal site is hosted on (Apache 1.3.33 and unknown version of
Ruby -
> >i'm trying to find out). but no matter what i try, i simply can not
> >get even the most minimal ruby script to function:
> >
> >#!/usr/bin/env ruby
> >
> >print "Content-type: text/html\n\n"
> >print "<html><body>Hello World!</body></html>\n"
> >
> >it runs perfectly fine at the console, no warnings, no errors, no
> >problems. but as a CGI script, it's another story: i get an error
500
> >and the cryptic (and seemingly common) "Premature end of script
> >headers". no other warnings or errors. if i simply change "ruby"
to
> >"python" on the shebang line, the above script magically works with
no
> >other effort on my part.
>
> This, actually, goes to the HTTP spec. Try this:
>
> #!/bin/env/ ruby
> print "HTTP/1.0 200 OK\r\n"
> print "Content-type: text/html\r\n\r\n"
> print "<html><body>Hello World!</body></html>\n"
>

does not work. see quoted below.

> >i'm going insane because nothing, AFAICT, is wrong. the server is
> >correctly set-up, permissions are correct, ownership is correct,
ruby
> >is installed and working, yet NOTHING seems to coax it into working.
> >it repeatedly reports this incredibly uninformative "Premature end
of
> >script headers" error.
> >
> >is there something i could have missed? a possible
misconfiguration?
> >or does ruby just hate me?
>
> E
>
> --
> template<typename duck>
> void quack(duck& d) { d.quack(); }

greyfade@gmail.com

5/23/2005 7:31:00 AM

0


James Britt wrote:
> greyfade@gmail.com wrote:
>
> Given this:
>
> > #!/usr/bin/env ruby
>
> What user is executing the script, and is ruby in that user's env?
>
the user(s) i control, in both cases, and yes, it is in the env. the
script works executing with the same command as in the shebang line
from a commond console.

> Try putting the literal path to Ruby there instead.
>
no effect.

again, i've tried everything. i still get an error 500, but *ONLY*
with ruby scripts. _no_other_language_ gives me this trouble.

>
> James

greyfade@gmail.com

5/23/2005 7:37:00 AM

0


Ara.T.Howard wrote:
> On Sun, 22 May 2005, greyfade@gmail.com wrote:
>
> > this is a problem that's been driving me nuts ever since i first
tried it.
> >
> > i can create simple, minimal scripts in Python, Perl, and PHP that
run
> > flawlessly on the first try with minimal effort, both on my local
testing
> > system (Apache 2.0.52 and Ruby 1.8.2) and on the server my personal
site is
> > hosted on (Apache 1.3.33 and unknown version of Ruby - i'm trying
to find
> > out). but no matter what i try, i simply can not get even the most
minimal
> > ruby script to function:
> >
> > #!/usr/bin/env ruby
> >
> > print "Content-type: text/html\n\n"
> > print "<html><body>Hello World!</body></html>\n"
> >
> > it runs perfectly fine at the console, no warnings, no errors, no
problems.
> > but as a CGI script, it's another story: i get an error 500 and
the cryptic
> > (and seemingly common) "Premature end of script headers". no other
warnings
> > or errors. if i simply change "ruby" to "python" on the shebang
line, the
> > above script magically works with no other effort on my part.
>
> nothing magic about it:
>
would it have been better if i'd said "works as expected" or "begins
working as expected" instead of "magically"? you seem to have missed
everything else in my post.

> or, put another way:
>
> harp:~ > ruby -e 'print 42' | od -c
> 0000000 4 2
> 0000002
>
> harp:~ > python -c 'print 42' | od -c
> 0000000 4 2 \n
> 0000003
>
>
> so you were just lucky that python and perl were sending you 'extra'
newline.
> you'd have even more issues if you did something like on a unix vs
windows box
> and it's the reason cgi abstraction are made.
>
irrelevant. running the script locally at a console produces the
expected result: ruby gives two newlines (resulting in one blank line)
after the Content-Type header and Python gives three newlines
(resulting in two). by my understanding, the extra newline in python
*SHOULDN'T* work.

>
> you'll also note that cgis are supposed to send '\r\n' not '\n\n' so
the other
> two never really should have worked anyhow ;-)
>
irregardless, they *DID*. so stop nitpicking and telling me things i
already know.

> > i'm going insane because nothing, AFAICT, is wrong. the server is
correctly
> > set-up, permissions are correct, ownership is correct, ruby is
installed and
> > working, yet NOTHING seems to coax it into working. it repeatedly
reports
> > this incredibly uninformative "Premature end of script headers"
error.
>
> this is because the script headers prematurely ended before the
content started
> since \r\n was never seen ;-)
>
not true. the script works in Python and Perl perfectly without
"\r\n". if that's out of spec, so be it. i'll be sure to obsrve the
spec in the future and use "\r\n" from now on.

but writing a script to produce *identical* output compared to the ruby
script in other programming languages WORKS FINE in CGI.
_RUBY_DOES_NOT_ and this is the issue i've come asking for help on.
your nitpicking on irrelevant details does not help to further anything.

greyfade@gmail.com

5/23/2005 8:13:00 AM

0

(apologies to ES for email.)

ES wrote:
> Le 21/5/2005, "greyfade@gmail.com" <greyfade@gmail.com> a écrit:
> >this is a problem that's been driving me nuts ever since i first
tried
> >it.
> >
> >i can create simple, minimal scripts in Python, Perl, and PHP that
run
> >flawlessly on the first try with minimal effort, both on my local
> >testing system (Apache 2.0.52 and Ruby 1.8.2) and on the server my
> >personal site is hosted on (Apache 1.3.33 and unknown version of
Ruby -
> >i'm trying to find out). but no matter what i try, i simply can not
> >get even the most minimal ruby script to function:
> >
> >#!/usr/bin/env ruby
> >
> >print "Content-type: text/html\n\n"
> >print "<html><body>Hello World!</body></html>\n"
> >
> >it runs perfectly fine at the console, no warnings, no errors, no
> >problems. but as a CGI script, it's another story: i get an error
500
> >and the cryptic (and seemingly common) "Premature end of script
> >headers". no other warnings or errors. if i simply change "ruby"
to
> >"python" on the shebang line, the above script magically works with
no
> >other effort on my part.
>
> This, actually, goes to the HTTP spec. Try this:
>
> #!/bin/env/ ruby
> print "HTTP/1.0 200 OK\r\n"
> print "Content-type: text/html\r\n\r\n"
> print "<html><body>Hello World!</body></html>\n"
>
not the case, apparently. it works happily with "\n" instead of "\r\n"
and doesn't seem to require the 200 header.

> >i'm going insane because nothing, AFAICT, is wrong. the server is
> >correctly set-up, permissions are correct, ownership is correct,
ruby
> >is installed and working, yet NOTHING seems to coax it into working.
> >it repeatedly reports this incredibly uninformative "Premature end
of
> >script headers" error.
> >
> >is there something i could have missed? a possible
misconfiguration?
> >or does ruby just hate me?
>

on one of my test servers, it turns out there is no ruby installed and
on another, it seems to be a major misconfiguration. so it seems
there's a lot i've missed as my original script runs unmodified on yet
another server.

> E
>
> --
> template<typename duck>
> void quack(duck& d) { d.quack(); }

greyfade@gmail.com

5/23/2005 8:20:00 AM

0


Ara.T.Howard wrote:
<snip a bunch of pointless drivel>

you missed everything i actually said in my post.

would it have helped if i had not said "magically worked" but instead
some more boring phrase like "worked as expected"? or would
"mystically worked" have thrown you off as well?

(if this message sounds condescending, it is. i was seriously offended
by the verbosity and tone of your post. apologies if you are
offended.)

> On Sun, 22 May 2005, greyfade@gmail.com wrote:
>
> > i'm going insane because nothing, AFAICT, is wrong. the server is
correctly
> > set-up, permissions are correct, ownership is correct, ruby is
installed and
> > working, yet NOTHING seems to coax it into working. it repeatedly
reports
> > this incredibly uninformative "Premature end of script headers"
error.
>
> this is because the script headers prematurely ended before the
content started
> since \r\n was never seen ;-)
>
it works without any linefeeds. newlines are sufficient in all my test
cases, irregarldess of my choice of language. all platforms are
unix-based, and i've not touched Windows in quite some time, so i'm
unsure of its behavior or requirements.

if it's out of spec, it doesn't seem to matter.

> > is there something i could have missed? a possible
misconfiguration? or
> > does ruby just hate me?
>
> doubtful ;-)
>
no, it turns out to be a major misconfiguration on my part. there is
something seriously wrong with one of my test environments. it works
on another server (one of my targets).

> -a
> --
>
===============================================================================
> | email :: ara [dot] t [dot] howard [at] noaa [dot] gov
> | phone :: 303.497.6469
> | My religion is very simple. My religion is kindness.
> | --Tenzin Gyatso
>
===============================================================================

ES

5/23/2005 6:10:00 PM

0


Le 23/5/2005, "greyfade@gmail.com" <greyfade@gmail.com> a écrit:
>
>Ara.T.Howard wrote:
><snip a bunch of pointless drivel>
>
>you missed everything i actually said in my post.
>
>would it have helped if i had not said "magically worked" but instead
>some more boring phrase like "worked as expected"? or would
>"mystically worked" have thrown you off as well?
>
>(if this message sounds condescending, it is. i was seriously offended
>by the verbosity and tone of your post. apologies if you are
>offended.)

Yours is quite a poor attitude to take toward people who
are attempting to assist you on their own time, for free,
particularly in light of A) your example not being exactly
valid HTTP and B) that it appears the problem was somewhere
else altogether.

Hopefully your issue is solved, now. If it is not, feel free
to askfor further advice but please try to do so with civility
and respect.

>> On Sun, 22 May 2005, greyfade@gmail.com wrote:
>>
>> > i'm going insane because nothing, AFAICT, is wrong. the server is
>correctly
>> > set-up, permissions are correct, ownership is correct, ruby is
>installed and
>> > working, yet NOTHING seems to coax it into working. it repeatedly
>reports
>> > this incredibly uninformative "Premature end of script headers"
>error.
>>
>> this is because the script headers prematurely ended before the
>content started
>> since \r\n was never seen ;-)
>>
>it works without any linefeeds. newlines are sufficient in all my test
>cases, irregarldess of my choice of language. all platforms are
>unix-based, and i've not touched Windows in quite some time, so i'm
>unsure of its behavior or requirements.
>
>if it's out of spec, it doesn't seem to matter.
>
>> > is there something i could have missed? a possible
>misconfiguration? or
>> > does ruby just hate me?
>>
>> doubtful ;-)
>>
>no, it turns out to be a major misconfiguration on my part. there is
>something seriously wrong with one of my test environments. it works
>on another server (one of my targets).
>
>> -a

E

--
template<typename duck>
void quack(duck& d) { d.quack(); }


Hal E. Fulton

5/24/2005 3:36:00 AM

0

greyfade@gmail.com wrote:

> it works without any linefeeds. newlines are sufficient in all my test
> cases, irregarldess of my choice of language. all platforms are
> unix-based, and i've not touched Windows in quite some time, so i'm
> unsure of its behavior or requirements.
>
> if it's out of spec, it doesn't seem to matter.

I think that's dependent on the web server, or is it the browser?
Too late for my poor brain.

Some are "looser" than others, but Ara is quite right in saying
that it is supposed to be a CRLF combination.

It really is better to code to the spec -- better to work 100%
of the time than 98%.


Cheers,
Hal