烧瓶和转印编码:分块 [英] Flask and Transfer-Encoding: chunked

查看:174
本文介绍了烧瓶和转印编码:分块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试让一个Flask Web服务正常工作,而且我们在传输文章时也遇到了一些问题 - 即当标题包含传输编码时:分块。

好像默认烧瓶不支持HTTP 1.1。有没有解决这个问题?

我们运行这个命令:

  $ curl -v -X PUT --headerTransfer-Encoding:chunked-d @pylucene-3.6.1-2-src.tar.gzhttp:// localhost:5000 / async-test

反对这个代码:

  @ app.route(/ async-test,methods = ['PUT'])
def result():
print'-------> '+ str(request.headers)+'< ------------'
print'------->'+ str(request.data)+' < ------------'
print'------->'+ str(request.form)+'< -------- ----'
return'OK'

这里是卷曲输出:

  $ curl -v -X PUT --headerTransfer-Encoding:chunked-d @pylucene-3.6.1-2-src .tar.gzhttp:// localhost:5000 / async-test
*关于连接()到localhost端口5000(#0)
* Trying :: 1 ...连接被拒绝
*尝试127.0.0.1 ...连接
*连接到本地主机(127.0.0.1)端口5000(#0)
> PUT / async-test HTTP / 1.1
> User-Agent:curl / 7.21.4(universal-apple-darwin11.0)libcurl / 7.21.4 OpenSSL / 0.9.8r zlib / 1.2.5
>主机:localhost:5000
>接受:* / *
> Transfer-Encoding:chunked
> Content-Type:application / x-www-form-urlencoded
>期望:100-继续
>
* HTTP 1.0,假设身体
< HTTP / 1.0 200 OK
< Content-Type:text / html; charset = utf-8
<内容长度:2
<服务器:Werkzeug / 0.8.3 Python / 2.7.1
<日期:2013年1月2日星期三21:43:24 GMT
<

这里是Flask服务器的输出:

  *在0.0.0.0:5000/ 
上运行-------> Transfer-Encoding:chunked
Content-Length:
用户-Agent:curl / 7.21.4(universal-apple-darwin11.0)libcurl / 7.21.4 OpenSSL / 0.9.8r zlib / 1.2.5
主机:localhost:5000
期望值:100-continue
接受:* / *
内容类型:application / x-www-form-urlencoded

<------------
------->< ------------
-------&&&& ImmutableMultiDict([])< ----- -------


解决方案

Python,它的mod_wsgi。只有mod_wsgi版本3.0+开始支持分块的http传输。 Flask Python内部使用Werkzeug工具包作为mod_wsgi的接口。如果你从apt源安装它,它可能是一个旧版本。



尝试编译最新版本的mod_wsgi,然后安装Flask框架,它可以解决问题。

We're trying get a Flask web service working, and we're having some issues with streaming posts - i.e. when the header includes Transfer-Encoding: chunked.

It seems like the default flask does not support HTTP 1.1. Is there a work around for this?

We are running this command:

$ curl -v -X PUT  --header "Transfer-Encoding: chunked" -d @pylucene-3.6.1-2-src.tar.gz "http://localhost:5000/async-test"

Against this code:

@app.route("/async-test", methods=['PUT'])
def result():
    print '------->'+str(request.headers)+'<------------'
    print '------->'+str(request.data)+'<------------'
    print '------->'+str(request.form)+'<------------'
    return 'OK'

Here's the curl output:

$ curl -v -X PUT  --header "Transfer-Encoding: chunked" -d @pylucene-3.6.1-2-src.tar.gz "http://localhost:5000/async-test"
* About to connect() to localhost port 5000 (#0)
*   Trying ::1... Connection refused
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 5000 (#0)
> PUT /async-test HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:5000
> Accept: */*
> Transfer-Encoding: chunked
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 2
< Server: Werkzeug/0.8.3 Python/2.7.1
< Date: Wed, 02 Jan 2013 21:43:24 GMT
<

And here's the Flask server output:

* Running on 0.0.0.0:5000/ 
------->Transfer-Encoding: chunked
 Content-Length:
 User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
 Host: localhost:5000
 Expect: 100-continue
 Accept: */*
 Content-Type: application/x-www-form-urlencoded

 <------------
 -------><------------
 ------->ImmutableMultiDict([])<------------

解决方案

Its not the Flask Python, its the mod_wsgi. Only mod_wsgi versions 3.0+ started to support chunked http transfers. Flask Python internally use Werkzeug tool-kit as an interface to mod_wsgi. If you installed it from the apt sources it may be an old version.

Try compiling the latest version of mod_wsgi and then install the Flask framework, it may solve the problem.

这篇关于烧瓶和转印编码:分块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆