How to run python script on my server?

I have a server running Blueshot. I use 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 it loaded onto my server, but it doesnโ€™t work ... If I go to the page, then it will just show the source code. I don't know if python is installed on my server (I believe python can be installed by default). How to check if python is running on my server, and if not, how can I run python scripts on my server? All I want to do is get POST variables from iPhone (I know how to send variables from iPhone) Thanks in advance ...

+4
source share
2 answers

Here is a small checklist of things to check when CGI scripts are not working:

  • Is it located in the cgi-bin (or equivalent)?
  • Is it executable?
  • Is it readable?
  • Does hashbang?
  • Is your server installed to handle CGI scripts?

Here is an example CGI script that 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 is executable:

 $ chmod a+rx test.py 

Some web servers only recognize CGI scripts with specific extensions, so if .py doesnโ€™t work, you can try .cgi .

+10
source

This is a web server configuration problem, not a programming problem.

If you are using 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 cannot run the ln command due to lack of access to the shell, just download with the .cgi extension to get started. Or, as icktoofay said, put it in your cgi-bin folder, you also won't need the .htaccess modification.

0
source

Source: https://habr.com/ru/post/1347851/


All Articles