问题标签 [wsgiref]

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 投票
1 回答
630 浏览

python - How to get WSGI servers to close a connection after each response?

The API for Python's wsgiref module precludes hop-by-hop headers (as defined in RFC 2616).

I'm unclear on how to get the server to terminate a connection after a response (since there doesn't seem to be a way to add Connection: close).

This problem comes up in testing small WSGI apps and Bottle micro-services. Calls from curl get blocked by open connections from a browser. I have to click a browser refresh to terminate the connection so that the pending curl request can be answers.

Obviously, this should be a server side decision (terminate connection after a response) rather than client-side. I'm unclear how to implement this.

0 投票
1 回答
1262 浏览

python - Python需要一个类似字节的对象,而不是'str'

我是 Python 新手。我正在运行以下简单的 Web 服务器:

不幸的是,我收到以下错误:

请建议我做错了什么。谢谢。

0 投票
1 回答
153 浏览

python - Python WSGIREF:在条件下终止服务器

我有以下代码:

Something()类的逻辑中,我根据某些逻辑递增或递减我存储在数据库中的计数器。我想s根据数据库上的条件调用线程。所以实际上,我正在尝试关闭服务器。我使用了http://code.nabla.net/doc/wsgiref/api/wsgiref/simple_server/wsgiref.simple_server.WSGIServer.html中的解释来做到这一点。但它似乎并没有杀死服务器。我究竟做错了什么?

0 投票
1 回答
151 浏览

python - Falcon, wsgiref : 单元测试用例

我有以下代码:

我尝试为以下内容创建以下测试用例:

我尝试运行上述但得到以下错误:

我实际上无法弄清楚我应该如何为此编写测试用例。

0 投票
1 回答
1560 浏览

python-3.x - 无法在 python 3.x 中安装 wsgiref

我无法在 python 3 中安装 wsgiref。我收到了这些错误。我正在使用 python 3,但我无法安装我尝试过pip install wsgiref的wsgirefpip install wsgiref==0.1.2

0 投票
1 回答
91 浏览

python - python wsgiref 自动重新加载

我尝试wsgiref用作如下服务器:

我想对我的整个代码使用自动重新加载。我应该怎么办?

0 投票
1 回答
47 浏览

python - 通过 HTTP 提供图像时损坏的图像

我在读取图像文件(.png、.jpg、.jpeg ...)时遇到问题,在终端中出现以下错误: UnicodeDecodeError: the 'utf-8' codec cannot decode the 0x89 byte in position 0 : invalid起始字节。我以为我已经通过声明 o_file = open ("cloud.png", "rb") 解决了这个问题,因为根据示例我不再在终端中收到错误,而是在查看文件 (cloud.png) 时出现错误以下:

在此处输入图像描述

我想知道为什么会发生这种情况以及如何在不使用第三方模块的情况下解决这个问题?下面是不使用python正常打开的文件的预览:

在此处输入图像描述

0 投票
0 回答
13 浏览

python - wsgiref simple_服务器无法得到对请求的响应

我尝试使用 wsgiref.simple_Server 模块来构建一个简单的 Web 服务器。我的服务器安装在 CentOS 上。每当服务器启动时,HTTP请求就成功了

一小时后,尝试了 HTTP 请求,但没有收到响应。检查服务器后台,没有报错,当然请求信息在几分钟前是固定的,没有请求信息刷新。当我尝试按 Ctrl + C 结束服务器时,控制台出现以下错误。

在此处输入图像描述

0 投票
0 回答
26 浏览

python - simple_server 从 wsgiref 中消失

几天来,我在 Windows 10 PC 上成功使用:

然后

我做了一些事情,因为现在我得到了 make server: AttributeError: module 'wsgiref' has no attribute 'simple_server' 我做了什么?如何解决问题?我重新安装了 Python 3.9.6,没有帮助。

0 投票
1 回答
40 浏览

python - 如何在 Python 中将参数传递给 wsgiref 应用程序?

wsgiref 应用程序函数必须如下所示:

start_response 只是一个函数,而 environ 没有用户设置的任何参数(https://www.python.org/dev/peps/pep-3333/#environ-variables)。
鉴于此,应用程序如何使用用户定义的变量而不使它们成为全局变量?