4

I have a server hosting by Blueshot. I have been using php to get post variables from iPhone... But now I have to use python to get post variable from iPhone. I wrote something like this

import cgi
import cgitb; cgitb.enable()  # for troubleshooting

print "Content-type: text/html"
print

print """
<html>

<head><title>Sample CGI Script</title></head>

<body>

  <h3> Sample CGI Script </h3>
"""

form = cgi.FieldStorage()
message = form.getvalue("message", "(no message)")

print """

  <p>Previous message: %s</p>

  <p>form

  <form method="post" action="index.cgi">
    <p>message: <input type="text" name="message"/></p>
  </form>

</body>

</html>
""" % message

And uploaded to my server but it doesn't work...If I navigate to the page then it just shows the source code.. I don't know whether or not python is installed on my server (I believe python might be installed as default)..How do I check if python is runnable on my server and if not how can I run python scripts on my server? All I want to do is to get POST variables from iPhone (I know how to send the variables from iPhone) Thanks in advance...

2 Answers 2

10

Here's a small checklist of things to check when CGI scripts aren't working:

  • Is it in a cgi-bin (or equivalent) folder?
  • Is it executable?
  • Is it readable?
  • Does it have a hashbang?
  • Is your server set up to process CGI scripts?

Here's a sample CGI script you can use for testing:

#!/usr/bin/env python
import cgi; cgi.test()

Name it test.py, put it somewhere in cgi-bin, and make sure it's executable:

$ chmod a+rx test.py

Some web servers only recognize CGI scripts with certain extensions, so if .py doesn't work, you may want to try .cgi.

Sign up to request clarification or add additional context in comments.

1 Comment

hashbang is important, +1. I always use it, but guess not everyone does
0

This is a webserver configuration problem not a programming issue.

If you're running Apache, this might work:


chmod 755 myscript.py
ln -s myscript.py myscript.cgi

Then put this in your .htaccess file:


AddHandler cgi-script .cgi

If you can't run the ln command because of no shell access, just upload with the .cgi extension to begin with. Or, as icktoofay said, put it in your cgi-bin folder, then you won't need the .htaccess modification either.

2 Comments

Then how to change the configuration?
@icktoofay: I know, I was typing, I'm slow :^\

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.