2015-09-19 67 views
0

我刚刚在Python中制作了一个服务器(仅用于localhost),以便由CGI执行并尝试我的Python脚本。这是文件的执行服务器上的代码:如何在CGI服务器中配置索引文件?

#!/usr/bin/env python 
#-*- coding:utf-8 -*- 

import BaseHTTPServer 
import CGIHTTPServer 
import cgitb 
cgitb.enable() ## This line enables CGI error reporting 

server = BaseHTTPServer.HTTPServer 
handler = CGIHTTPServer.CGIHTTPRequestHandler 
server_address = ("", 8000) 
handler.cgi_directories = ["/"] 

httpd = server(server_address, handler) 
httpd.serve_forever() 

当我在服务器访问某些脚本(http://127.0.0.1:8000/index.py)是没有问题的,但是当我访问服务器(http://127.0.0.1:8000/)它表明:

Error response 

Error code 403. 

Message: CGI script is not executable ('//'). 

Error code explanation: 403 = Request forbidden -- authorization will not help. 

这就像如果索引文件没有被设置为默认的文件访问文件夹,而不是特定的文件的时候访问...

我希望能够在我访问http://127.0.0.1/来访问http://127.0.0.1/index.py。谢谢你的一切。

回答

0

Python的内置HTTP服务器是非常基本的,所以它不包含这样的功能。但是,您可以通过继承CGIHTTPRequestHandler来实现它,可能会替换is_cgi函数。

0

如果使用handler.cgi_directories = ["/cgi"],则可以在“/”中放置index.html文件。当然,如果你想要一个cgi脚本index.py作为默认值,你可以使用index.html转发...

相关问题