python - 使用 python 3.8 使用 aiohttp 从服务器发出空回复

标签 python response python-3.8 aiohttp

我正在尝试使 aiohttp 工作,但最简单的代码可能无法工作。该问题仅存在于从源代码编译的特定开发服务器上。

以下代码产生以下输出:

from aiohttp import web

async def hello(request):
    return web.Response(text="Hello, world")

app = web.Application()
app.add_routes([web.get('/', hello)])

web.run_app(app)

我从服务器得到一个空回复(wget 产生相同的输出)

# ./curl-amd64 http://localhost:8080/ -v
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.75.0
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer

我正在自定义构建的 Linux 内核 5.3.18 上运行 python 3.8.1。 Pip 在本地系统上可用。 当我运行 pip install aiohttp 时,所有依赖项都满足,收到响应。

# pip install aiohttp
Requirement already satisfied: aiohttp in /usr/lib/python3.8/site-packages (3.5.4)
Requirement already satisfied: attrs>=17.3.0 in /usr/lib/python3.8/site-packages (from aiohttp) (19.3.0)
Requirement already satisfied: chardet<4.0,>=2.0 in /usr/lib/python3.8/site-packages (from aiohttp) (3.0.4)
Requirement already satisfied: multidict<5.0,>=4.0 in /usr/lib/python3.8/site-packages (from aiohttp) (4.5.2)
Requirement already satisfied: async_timeout<4.0,>=3.0 in /usr/lib/python3.8/site-packages (from aiohttp) (3.0.1)
Requirement already satisfied: yarl<2.0,>=1.0 in /usr/lib/python3.8/site-packages (from aiohttp) (1.3.0)
Requirement already satisfied: idna>=2.0 in /usr/lib/python3.8/site-packages (from yarl<2.0,>=1.0->aiohttp) (2.8)
#

此问题仅存在于该特定系统上。当我将代码复制到另一台机器(例如 Mac)时,服务器响应良好。

系统中是否缺少任何内容(系统库、共享模块等)可能导致此问题?

最佳答案

将软件包升级到最新版本有帮助。

aiohttp==3.7.4.post0

关于python - 使用 python 3.8 使用 aiohttp 从服务器发出空回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66855708/

相关文章:

python - dev_appserver.py 说未知运行时 'python38'

python - 如何在 python discord bot 中获取用户输入?

python - 为什么我收到 TypeError : must be str, 而不是builtin_function_or_method?

Python战舰随机数生成器

python - Eigen + MKL 或 OpenBLAS 比 Numpy/Scipy + OpenBLAS 慢

Node.js 混淆每个循环的输出

json - 收集资源的响应有效负载主体的建议

Python selenium - 与主机、端口、用户名、密码的代理连接

C#向外部URL发送信息并打开

python - 如何连接来自 3 个小整数的字节以生成由 Python 中的这些字节表示的更大数字?