首页 > 解决方案 > Python + Curl - 如何修复“来自服务器的空回复”

问题描述

我使用https://gist.github.com/bradmontgomery/2219997 python 代码来设置一个 http 服务器。对于我的使用,我只是在 'do_POST' 方法中添加了几行:

def do_POST(self):
        self._set_headers()
        self.wfile.write("POST!")
        content_length = int(self.headers['Content-Length'])
        print(content_length )
        post_data = self.rfile.read(content_length)
        print(post_data)

我想通过 Curl 发送文件:

curl -F "file=@file.txt" "http://myServer.noip.me:22222/" --trace-ascii debugdump.txt

客户端:卷曲响应是:

 curl: (52) Empty reply from server

服务器端:服务器打印 content_length 值,然后在“self.rfile.read(content_length)”行完全挂起。它不打印“打印(post_data)”。

双方的防火墙均已禁用。

debugdump.txt(客户端)的最后几行:

== Info: Empty reply from server
== Info: Connection #0 to host myServer.noip.me left intact

我错过了什么?

标签: pythoncurl

解决方案


Empty reply from server意味着服务器关闭了连接而没有响应任何违反 HTTP 协议的内容。

这不应该发生在适当的服务器上,因此它表明服务器端出现严重错误。

有时会发生这种情况,因为服务器的实现很天真,并且在来自客户端的意外请求时崩溃或行为不端。完成这项工作的最佳机会是尝试以某种方式更改请求,使其更类似于编写糟糕的服务器软件可能期望的方式。

这是一个猜测的问题。你的那台服务器有问题。


推荐阅读