问题标签 [basehttpserver]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1294 浏览

sqlite - Python - BaseHTTPServer,POST 和 GET 问题

我正在制作一个非常简单的应用程序,其中包含 2 个网页,网址为:localhost:8080/restaurants/ 和 localhost:8080/restaurants/new。我有一个 sqlite 数据库,我在我的 python 代码中使用 SQLAlchemy 进行操作。

在我的第一页 localhost:8080/restaurants/ 上,它只包含我的数据库中可用的餐馆列表。我的第二页 localhost:8080/restaurants/new,是我有一个表格以便新餐厅显示在 localhost:8080/restaurants 上。但是,每当我在 localhost:8080/restaurants/new 的表单上输入新餐厅名称时,它都无法将我重定向回 l​​ocalhost:8080/restaurants/ 以向我展示新餐厅,而是保留在相同的 url 链接上localhost:8080/restaurants/new 带有消息 "No data received" 。下面是我的代码:

供参考的是我在其中创建数据库的 database_setup 文件:

我不知道为什么我不能添加新的餐厅

0 投票
1 回答
55 浏览

python - Python 脚本无法启动,涉及“子进程”

这只是随机决定对自己废话,错误:

http://creeper9207.com/error.PNG

其他信息:Windows 10 beta Build 9926 python 2.7.9 空闲和终端错误,终端太快看不到

0 投票
1 回答
482 浏览

python - BaseHTTPServer,从 POST 单个值中提取变量

我想知道如何使用位于外部服务器上的 html 表单获取变量表单内容。

我有这个代码:

我的服务器.py

它目前在控制台上打印

我想提取每个变量并使用它们来调用后续的 bash 脚本。

我想要完成的例子:

感谢您的评论和帮助。

0 投票
2 回答
81 浏览

python - BaseHTTPServer,仅在我的变量发布后接收

嗨,我的变量帖子有此代码,我希望它始终监听和接收帖子请求,工作正常,但在收到第一个变量后,脚本运行但不再获取帖子变量。

只能运行一次,然后必须重新启动 python 脚本。

谢谢大家

0 投票
1 回答
813 浏览

python - 在 python 中将 BaseHttpServer 连接到 WSGI

我正在学习他们使用 BaseHTTPServer 的 python 课程。他们开始的代码在这里

我在任何地方都在使用 python,而将应用程序放到 Internet 上的唯一可能性是使用 wsgi 接口。

wsgi 接口的配置文件如下所示:

应用程序可能是这样的:

HELLO_WORLD 将是一个带有 html 内容的字符串。

我不能像示例中那样只指向端口 8080。为了在任何地方使用 python,我必须同时连接两者。我认为 wsgi 可能是从 BaseHTTPServer 派生的,因此可以连接它们并在 pythonanywhere.com 上使用我的课程

很明显,我必须摆脱 main 函数中的代码并改用 application 函数。但我并不完全了解这是如何工作的。我得到一个我调用的回调(start_response)然后我产生内容?如何将它与 webServerHandler 类结合使用?

如果这是可能的,理论上它应该也适用于谷歌应用引擎。我在这里找到了一个使用 BaseHTTPServer 的非常复杂的示例,但这对我来说太复杂了。

是否有可能做到这一点,如果是的话,有人可以给我一个提示如何做到这一点并为我提供一些基本的起始代码吗?

0 投票
1 回答
1445 浏览

python - 无法使用 SocketServer 和 BaseHTTPServer 在本地目录中提供文件

这是使用 python 2.7.6

我正在尝试从我的本地当前工作目录提供文件。我正在尝试设置从该目录运行的服务器,但无法显示其任何文件。

我一直在尝试运行此处找到的代码来设置一个服务器,该服务器在当前目录中侦听 http 请求,但没有任何运气可以让文件显示。

我一直在尝试显示images.html此目录中存在的 html 文件,但是当我运行以下脚本并在浏览器中导航到 127.0.0.1:8000/images.html 时,我只得到一个空白页。尝试导航到 127.0.0.1:8000/ 以显示目录内容时也会发生这种情况。

当我导航到 127.0.0.1:8000/images.html 时,服务器正在运行,我得到了预期的命令行输出:

但是,如果我运行

从当前目录导航到 127.0.0.1:8000/images.html,html 文件确实按预期显示。

我错过了什么?

0 投票
0 回答
2121 浏览

python-2.7 - 文件上传错误没有与给定的 URI 匹配

我正在尝试使用 python 2.7 请求和 BaseHTTPServer 上传文件,这是服务器 POST 配置

客户端很简单

我收到的错误消息是“没有与给定的 URI 匹配”。

有没有人有任何提示可能是什么问题?

0 投票
1 回答
186 浏览

python - How can I safely update the handler of a BaseHTTPServer under Linux?

I'm trying to write a program that changes the content of a webpage with some user given parameters. After several tries and some googling, i've managed to get some results (I put the webserver in a thread in order to continue other tasks in the main routine). It seems to run pretty smooth in windows, but I always got a

socket.error: [Errno 98] Address already in use

when I try it from my linux machine (the whole thing must run on raspian at the end).

I read something here that explains that the SO_REUSEADDR socket option (I think it concerns with) have different behaviours among different OS (and, if I haven't misunderstood, it "works" on Windows thanks to a bug), but I can't find a solution to get it work this way on Linux for this option is already set to True by default.

Here's a simplified absract of the code that generates the error:

with this module (web.py)

Is there a real solution to get rid of this error? Or is there a better way to manage the handler in orger to acchieve my goal?

EDIT: the error occurs after the input of the "2nd content". The 1st instance runs flawlessly, so I can tell for sure that the socket is not used by anything else.

Thanks to all!

0 投票
1 回答
572 浏览

jquery - 用于与 jsonp 通信的简单 Python HTTP Server

我正在尝试在 python 服务器和网络浏览器之间使用 jsonp 交换数据。客户端看起来像这样(使用 jQuery)并且工作得很好:

在初始 init 行之后,python 服务器套接字到达如下字符串:

现在我想返回一个这样的字符串('reply'包含'that is a test':

对于通信,我现在使用一个简单的套接字。但这并不是很好。我搜索了一个更高级别的解决方案。所以我现在想使用 BaseHTTPServer 并改为子类 do_GET(self) 。但是我不知道如何实现上面的通信。有人可以帮忙吗?

0 投票
2 回答
1186 浏览

python - 为什么host http server 需要指定它所托管的IP?

我使用 BaseHTTPServer 模块在 Python 上托管一个 http 服务器。

我想了解为什么需要指定托管 http 服务器的 IP,例如 127.0.0.1/192.168.0.1 或其他。[可能是一个通用的 http 服务器概念,而不是特定于 Python]

为什么不能像知道机器IP的任何人都可以连接到http服务器?

如果我的 http 服务器同时连接到两个网络,并且我想在两个网络上都为 http 服务器提供服务,我会遇到问题。当我从 http 服务器机器上的热点模式切换到连接到另一个 wifi 路由器时,我的 IP 通常会即时更改。