Python 发送多部分/表单数据时获取断管故障

Python 发送多部分/表单数据时获取断管故障,python,http,curl,Python,Http,Curl,我正在尝试设置一个服务器来处理python中的多部分表单数据。我正在尝试使用curl命令访问python服务器 我遇到了Pip失败错误 有人能帮忙吗 PYTHON服务器代码: from BaseHTTPServer import BaseHTTPRequestHandler import cgi import cgitb cgitb.enable(display=0,logdir="") class PostHandler(BaseHTTPRequestHandler): def d

我正在尝试设置一个服务器来处理python中的多部分表单数据。我正在尝试使用curl命令访问python服务器

我遇到了Pip失败错误

有人能帮忙吗

PYTHON服务器代码:

from BaseHTTPServer import BaseHTTPRequestHandler
import cgi
import cgitb
cgitb.enable(display=0,logdir="")

class PostHandler(BaseHTTPRequestHandler):

    def do_POST(self):
        print self.headers
        expect = self.headers['Expect']
        self.protocol_version='HTTP/1.1'
        print "Expect %s " % (expect)
        if expect.startswith('100') :
            print "Entered Expect section %s " % (self.protocol_version)
            self.send_response(100)
            print self.protocol_version
            #self.send_header("Content-Length","0")
            self.end_headers()
        else:
            con_length = int(self.headers['Content-Length'])
            print con_length
            content_type = self.headers['Content-Type']
            print content_type
            if content_type.startswith('multipart/form-data') :
                self.send_response(100)
                self.end_headers()
                self.wfile.write("Data:Krishnan");
                #self.rfile.read(con_length)
            else :
                print self.rfile.read(con_length)

                #Send the Response

                self.send_response(200)
                self.end_headers()
                self.wfile.write("Data:Krishnan")
        return

if __name__ == '__main__':
    from BaseHTTPServer import HTTPServer
    server = HTTPServer(('localhost',8000),PostHandler)
    print "Started Serving on HTTP Port 8000"
    server.serve_forever()
点击服务器的CURL命令:

curl-ivhttp://localhost:8000 -F myfile=@/home/local/krishnan/messages.gz“

卷曲反应:

* About to connect() to localhost port 8000 (#0)
*   Trying 127.0.0.1... connected
> POST / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:8000
> Accept: */*
> Content-Length: 4105
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------1ca123daf202
> 
< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue
< Server: BaseHTTP/0.3 Python/2.7.3
Server: BaseHTTP/0.3 Python/2.7.3
< Date: Wed, 13 Aug 2014 15:21:23 GMT
Date: Wed, 13 Aug 2014 15:21:23 GMT

* Send failure: Broken pipe
* Closing connection #0
curl: (55) Send failure: Broken pipe
*即将()连接到本地主机端口8000(#0)
*正在尝试127.0.0.1。。。有联系的
>POST/HTTP/1.1
>用户代理:curl/7.22.0(x86_64-pc-linux-gnu)libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
>主机:localhost:8000
>接受:*/*
>内容长度:4105
>预期:100人继续
>内容类型:多部分/表单数据;边界=------------------------------------1ca123daf202
> 

请帮帮我

当您检测到
Expect:100 continue
时,您只需响应
100 continue
,然后关闭连接。发送
100后,继续
您需要读取请求正文,如果没有问题,请用
200 OK
响应

def do_POST(self):
 ....
     self.send_response(100)
     self.end_headers()
     con_length = int(self.headers['Content-Length'])
     data = self.rfile.read(con_length)
     self.send_response(200)
     self.end_headers()

还可以查看一下

谢谢,现在我可以读取文件的内容,但无法在curl端结束连接。我得到了错误
没有区块,没有闭合,没有大小。假设靠近信号端
。你知道怎么摆脱它吗?