python - 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
我错过了什么?
解决方案
Empty reply from server
意味着服务器关闭了连接而没有响应任何违反 HTTP 协议的内容。
这不应该发生在适当的服务器上,因此它表明服务器端出现严重错误。
有时会发生这种情况,因为服务器的实现很天真,并且在来自客户端的意外请求时崩溃或行为不端。完成这项工作的最佳机会是尝试以某种方式更改请求,使其更类似于编写糟糕的服务器软件可能期望的方式。
这是一个猜测的问题。你的那台服务器有问题。
推荐阅读
- django - 如何通过 post 方法在 django-restful-framework 中创建新对象?
- python - 当我尝试在 jpeg 中转换 pdf 时发生多个错误
- node.js - 如果数据太大,Socket.io 不会发出
- django - 有人可以让我理解这里的真正问题吗?Django 新手
- javascript - 任何人都可以在此 js 代码中找到错误吗?
- c# - C# 从浏览器窗口抓取 HTML
- java - 如何使用 Glide 共享从服务器加载到图像视图中的图像
- ocr - 从手写填写的表格中提取表格数据到 CSV 数据
- python - 有没有办法将 csv 作为字典读取并在输出中添加一些字段?
- google-calendar-api - 免费与 Salesforce 集成