FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Python CGI script 500 error





Radar
Hey, I've recently signed up, joining Server 3, and I'm struggling to get past a 500 internal server error on a Python CGI script.

The HTML file (not that it could really be this) -
<html>
<head>
<title>Test</title>
</head>
<p>
<form action="cgi-bin/query.cgi" method="GET">
<input type="text" name="search">
<input type="submit" name="Submit"></form>
</body>
</html>

The CGI file -
#!/usr/bin/python

import cgi
print "Content-type: text/html"
print
print
print "<HTML><H1>Hello</H1></HTML>"

They both very basic because at this stage I can't even get that to work. I've applied chmod 755, searched around a good deal, but can't seem to find anything to help me.

If this is as basic as I think it must be I apologise, but thanks to anyone who can help me.
Radar
If it helps, I've found that the error log says that there is a 'Premature end of script headers'.

Any replies at all are welcome.
AftershockVibe
Does the error occur when you click submit or when you load the page?
Radar
When I've hit 'Submit' - I really think it should be an error with the cgi file, rather than the HTML file.

Calling the CGI file directly should work if it were just the HTML file, but that doesn't work either.
Radar
Okay, I've now worked out that there are cgi scripts that work on another host I'm using, but not FriHost. This means that it's not the script itself, but something unique to FriHost - the .htaccess file or something similar.

Anything? Anyone? Thanks again.
quasar
I dont know Python ... Crying or Very sad ... but I do not know what the reason of cgi library in your script? Perhaps the the script works in removing the import.

After Content-type there should be two blank lines. Does the print function insert these lines? Or should be printlln?

Bye Speak to the hand
Radar
Yeah, no, Python cgi scripts do need to import that library, and the print function does insert the required blank lines.

I've now become aware that others - http://www.frihost.com/forums/vt-98189.html - are having issues with Python on Server 3 - http://www.frihost.com/forums/vt-97899.html - and so this is a more general problem than just me.

That's good, or bad, depending on which way you look at it.
quasar
Try this

print "Content-type: text/html"
print "\r\n\r\n"
Radar
I did try that, and it still didn't fix the problem - but as I've already said, it could be Server 3 in general, and shouldn't be my script itself anyway since I can get it succesfully working on another service.

And carriage returns shouldn't be an issue, since I have tried just editting it in the online text editor, still to no avail.

Thanks for your suggestion though.
toxictux
try running the same on your personal computer. see what kind of HTML it generates. may be try it on server in a shell.

run python script.py and you might spot some problem
Radar
Ah....thanks to those who keep replying, but this issue is kind of over, since I've now decided that it's Server 3 not having Python, rather than anything that I've done, being the source of the problem.
toxictux
did you manage to get your account moved to a different host ? i am trying to do the same. i have sent message to bondings but no reply so far.
Radar
Hey,

No, my account hasn't been moved. As you said - http://www.frihost.com/forums/viewtopic.php?p=830832 - it doesn't look like account changes are being looked at.

Here - http://www.frihost.com/forums/vt-99805.html and http://www.frihost.com/forums/vp-823337.html - it is in fact said that server changes aren't possible. You've probably seen one or both of those, but for the benefit of others reading this I'm listing it anyway.
toxictux
finally, no need to move the account to any other server. I can confirm that Python is now working on server 3. bondings installed it few days back. you just need to put your script in cgi-bin directory.


Following works for me.

1. create a file tes.py in public_html/cgi-bin directory
2. put following in a file test.py

Code:

#! /usr/bin/env python

print "Content-type: text/html"
print
print "<html>"
print "<center>Hello, Pythonic World....</center>"
print "</html>"



3. change the permission to 755 and. call the script in the browser and there you have it.
Radar
I'm still getting an error, but hunting around I did find - http://www.frihost.com/forums/vt-98631.html - bondings talking about it. Maybe I just need to sit down and bang my head against it again for a few hours, but I'm kind of reluctant given all the trouble I've had in the past.

And just while we're here - a few days? Try beginning of December. Given the number of people that were coming up against this problem, I'm surprised that this didn't come up in this topic until now.
nguyenvulong
Sorry for digging up this post.
I'm on server 4 and I did all of your suggestion above but not succeed.

Anyone have a python script running on Server 4 ? Please gimme some tips, thanks ! Exclamation
Bondings
nguyenvulong wrote:
Sorry for digging up this post.
I'm on server 4 and I did all of your suggestion above but not succeed.

Anyone have a python script running on Server 4 ? Please gimme some tips, thanks ! Exclamation

Python is not available anymore on Server 4. If you want Python, please request a transfer to Server 2/3 (and I'll make sure to get it working there).
Related topics
Python beginners help!
Python CGI work with FRIHOST
Problem with python cgi - does Python CGI work?
Convert CGI script to php and MySQL
Python via CGI - A personal triumph
Python via CGI - A personal triumph
cgi script outsite cgi-bin
Is there a Python Hello World using Apache?
CGI-script
500 Error/Datebase Error for the past 48+ hours
Executing a Perl CGI script
after server 4 crash I have a 500 error code
Showing 500 error on my cPanel page what to do??? HELP!!!!
Tutorial needed for python cgi
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.