You are invited to Log in or Register a free Frihost Account!

Python CGI script 500 error

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) -
<form action="cgi-bin/query.cgi" method="GET">
<input type="text" name="search">
<input type="submit" name="Submit"></form>

The CGI file -

import cgi
print "Content-type: text/html"
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.
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.
Does the error occur when you click submit or when you load the page?
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.
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.
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
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 - - are having issues with Python on Server 3 - - and so this is a more general problem than just me.

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

print "Content-type: text/html"
print "\r\n\r\n"
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.
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 and you might spot some problem
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.
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.

No, my account hasn't been moved. As you said - - it doesn't look like account changes are being looked at.

Here - and - 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.
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 in public_html/cgi-bin directory
2. put following in a file


#! /usr/bin/env python

print "Content-type: text/html"
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.
I'm still getting an error, but hunting around I did find - - 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.
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
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?
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

© 2005-2011 Frihost, forums powered by phpBB.