How to set up cgi

unobtainium

New Member
Messages
5
Reaction score
0
Points
0
The calling page containing the form submitting the request to a python script in cgi-bin works on my personal server. It fails when I load it up on x10hosting. Obviously, it is not set up properly. How to do that?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
This topic has been covered before. Search for the relevant threads. If you're still having problems, post your specific problem, including what you've done, a link to a live page, what you expect to happen and what actually happens, including any error messages. We're not psychic.
 

unobtainium

New Member
Messages
5
Reaction score
0
Points
0
I did search and came up with nothing.
Please suggest how to reach one of those threads.
 

dlukin

New Member
Messages
427
Reaction score
25
Points
0
So much for the helpful members of this forum.

1. Make sure the script has permissions set to 0755
2. Script should have rough outline like:

Code:
#!/usr/bin/env python
import os
import sys

print("Content-type: text/html")
print("")

print("<html>")
print("<body>")

print( "GET / POST Information")
print("<pre>")


print "Request method: " , os.environ[ 'REQUEST_METHOD' ]
print "Query string: " ,  os.environ[ 'QUERY_STRING' ]
count = 0 
for line in sys.stdin:
    count = count + 1
    print line
    if count > 100:
        break
print ""
print("</pre>")
print("</body>")
print("</html>")

Make sure you print out the HTTP Content header before any output. Follow it by a blank line. They are running Python 2.6 I think. Definitely not 3.

3. If the script is in cgi-bin , you should be set to go
If it is anywhere else, make sure you have a line:

Code:
AddHandler cgi-script .py

in your .htaccess file

4. If your script still flubs, post any error messages back here and I can try to help.
 

unobtainium

New Member
Messages
5
Reaction score
0
Points
0
Thank you so much.
I was totally unaware of how to set permissions.
I just tried FileZilla and it worked.
Now, cgi works just fine.
Thank you.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Please suggest how to reach one of those threads.
The first link in my first post is to a search that lists those threads (hence the sig). The first result shows how to access input variables. The second (and other) results tell you about permissions. Both have sample scripts.
 
Last edited:
Top