开发者

How to execute a python cgi-script under Linux

I have a python cgi script which executed fine on a Windows machine simply by starting CGIHTTPServer in the console, opening the html page to pass the data to the script and submitting the data.

I now need to do this under Linux but this is proving more difficult. Some web searching has given this script to start the server (I've put in 8开发者_如何转开发000 as the original 80 didn't work)

 import os  
 import BaseHTTPServer, CGIHTTPServer  
 serverAddr = ("", 8000)  
 os.chdir("/home/apannife/www")  
 serv = BaseHTTPServer.HTTPServer( \  
     serverAddr, CGIHTTPServer.CGIHTTPRequestHandler)  
 serv.serve_forever()  

the html.

<HTML><HEAD><TITLE>

Test

</TITLE>

</HEAD>

<BODY>

<B>  Filename </B>

<FORM METHOD=post ACTION="cgi-bin/docking_cgi.py" ENCTYPE="multipart/form-data">

<INPUT Type="file" NAME="upfile" SIZE=45><BR>

<P><INPUT TYPE=submit></FORM>



</BODY></HTML>

and the first part of the cgi.

#!/usr/bin/env python

import cgi

from cgi import FieldStorage


reshtml = '''Content-Type: text/html\n

<HTML><HEAD><TITLE>

DEMO

</TITLE></HEAD>

<BODY><H3> OUTPUT SENT TO %s %s </H3>

</BODY></HTML>'''
form = cgi.FieldStorage()

upfile = form['upfile']

However submitting the data just returns the text of the cgi script and doesn't run it. I've chmod-ded 775 everything in sight and it looks like the server is not automagically understanding that I want it to execute the script. How do I make it do so? thanks.


The server only executes scripts under the directories /cgi-bin and /htbin relative to the server root. In contrast to Windows, these names are case-sensitive on Linux.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜