- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我简单地创建了一个 python 服务器:
python -m SimpleHTTPServer
我有一个 .htaccess(我不知道它是否对 python 服务器有用)与:
AddHandler cgi-script .py
Options +ExecCGI
现在我正在编写一个简单的 python 脚本:
#!/usr/bin/python
import cgitb
cgitb.enable()
print 'Content-type: text/html'
print '''
<html>
<head>
<title>My website</title>
</head>
<body>
<p>Here I am</p>
</body>
</html>
'''
我使 test.py(我的脚本的名称)成为一个执行文件:
chmod +x test.py
我在 firefox 中使用这个地址启动:(http ://) 0.0.0.0:8000/test.py
问题,脚本没有执行...我看到网页中的代码...服务器错误是:
localhost - - [25/Oct/2012 10:47:12] "GET / HTTP/1.1" 200 -
localhost - - [25/Oct/2012 10:47:13] code 404, message File not found
localhost - - [25/Oct/2012 10:47:13] "GET /favicon.ico HTTP/1.1" 404 -
如何简单地管理python代码的执行?是否可以在 python 服务器中编写来执行 python 脚本,就像这样:
import BaseHTTPServer
import CGIHTTPServer
httpd = BaseHTTPServer.HTTPServer(\
('localhost', 8123), \
CGIHTTPServer.CGIHTTPRequestHandler)
### here some code to say, hey please execute python script on the webserver... ;-)
httpd.serve_forever()
或者别的……
最佳答案
CGIHTTPRequestHandler
你走在正确的轨道上,因为 .htaccess
文件对内置的 http 服务器没有任何意义。有一个 CGIHTTPRequestHandler.cgi_directories
变量指定可执行文件被视为 cgi 脚本的目录 (here is the check itself)。您应该考虑将 test.py
移动到 cgi-bin
或 htbin
目录并使用以下脚本:
cgiserver.py:
#!/usr/bin/env python3
from http.server import CGIHTTPRequestHandler, HTTPServer
handler = CGIHTTPRequestHandler
handler.cgi_directories = ['/cgi-bin', '/htbin'] # this is the default
server = HTTPServer(('localhost', 8123), handler)
server.serve_forever()
cgi-bin/test.py:
#!/usr/bin/env python3
print('Content-type: text/html\n')
print('<title>Hello World</title>')
你应该得到:
|- cgiserver.py
|- cgi-bin/
` test.py
使用 python3 cgiserver.py
运行并将请求发送到 localhost:8123/cgi-bin/test.py
。干杯。
关于python - 如何在python创建的BaseHTTPSERVER上执行python脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13065306/
我有一个基于 BaseHTTPServer 的简单服务器的以下代码。 class myHandler(BaseHTTPRequestHandler): #Handler for the GET
我的代码很简单。使用 BaseHTTPServer 和 ThreadInMix 我想运行每个同时发出的请求的 python 脚本 (Script1.py)。 我的代码- 从子进程导入 PIPE,P
您好,我有这个代码用于我的变量发布,我希望它始终监听和接收发布请求,工作正常,但在接收到第一个变量后,脚本运行但不再获得发布变量。 只能正常运行一次,然后必须重新启动 python 脚本。 impor
我正在使用 BaseHttpServer 类的方法“do_GET”。 我想做的是连续调用这个方法可以访问同一个共享变量 如果我发送第一个命令 0 然后 1,我将无法访问同一个变量 from BaseH
我正在尝试为 javascript 编写一个简单的本地代理:因为我需要从网页中的 javascript 加载一些东西,所以我用 python 编写了这个简单的守护进程: import string,c
这是我的: http.py: class HTTPServer(): def __init__(self, port): self.port = port se
我正在尝试评估各种语言以构建小型高吞吐量应用程序服务器。它需要做一些小事情,比如获取请求、从运行缓存应用程序(memcached、redis)的单独服务器读取数据,以及发回 5 - 10 行 XML
为了允许帮助台重新启动 Oracle 实例,我们正在尝试实现一个小型 python Web 服务器,该服务器将启动启动 Oracle 实例的 shell 脚本。 代码已完成,它启动了实例,但有一个问题
我使用 BaseHTTPServer 编写了一个快速的网络服务器,它工作得很好,所以现在我正在尝试实现日志记录,我注意到,嘿,似乎 BaseHTTPServer 已经有一些日志信息输出到标准输出,是吗
我正在尝试使用 BaseHttpServer 和 ThreadingMixIn 创建一个多线程网络服务器(如各种示例所示)。伪代码类似于: class Handler(BaseHTTPRequestH
引用:http://docs.python.org/2/library/basehttpserver.html 我有以下代码片段,它使用 Python BaseHTTPServer 来运行基本的 HT
根据来源,BaseServer.shutdown() 必须从与运行服务器的线程不同的线程调用。 但是,我试图通过在 Web 请求中向服务器提供特定值来关闭服务器。 请求处理程序显然在这个线程中运行,所
有没有办法让 BaseHTTPServer.HTTPServer 像 SocketServer.ThreadingTCPServer 一样是多线程的? 最佳答案 您可以简单地使用使用这两个类的线程混合
我有以下 python 代码,其中我通过扩展 HTTPBaseServer 编写了一个简单的 HTTP 服务器: class ApiError(Exception): def __init__
我正在构建一个基于 python 的网络服务器( 是的,python 对于网络服务器来说是一个糟糕的选择,但这是我唯一的选择还有另一个很好的选择可以满足我的目的,例如 PHP,但我仅限于 python
我正在编写一个非常基本的网络服务器(好吧,正在尝试),虽然它现在可以很好地提供 HTML,但我的 CSS 文件似乎根本无法被识别。我的机器上也运行着 Apache2,当我将文件复制到 docroot
我有下一个 python 代码: from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import os PORT_NUMBER
我正在尝试使用 Python2.7 中的 BaseHttpServer 来制作一个简单的 HTTP SERVER,问题是当我想通过 在浏览器上设置多个 cookie 时 self.send_
我有调用外部 HTTP 服务的 Python 代码。我想通过设置模仿这些外部服务的模拟 HTTP 服务器来测试此代码。为此,我在一个单独的线程中启动一个 BaseHTTPServer,然后从主线程调用
因此,我尝试按照有关如何使用 web.py 的在线教程进行操作,并且安装了它,但不幸的是,使用这段代码会产生严重的错误。我的代码... import web urls = ( '/(.*)',
我是一名优秀的程序员,十分优秀!