Python请求发送流文件和龙卷风来接收它

时间:2013-10-11 12:47:49

标签: python post streaming tornado

我有一个名为''的文件,里面有随机数字。 有一个代码用这个文件发送post请求,但是作为一个流,而不是普通的POST文件:

with open('stream-file') as f:
   requests.post('http://localhost:8888/service', data=f)

现在,有一个龙卷风服务器正在运行,它会抓住这个帖子并且应该读取它(使用块,而不是一起):

import tornado.ioloop
import tornado.web
import tornado.options

class ServiceHandler(tornado.web.RequestHandler):
    def post(self):
        # here code to read this streamed file byte by byte.
        pass

application = tornado.web.Application([
    (r"/service", ServiceHandler)
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

有人能给我一个如何使用它的提示吗? 我找到了这个例子:https://gist.github.com/nephics/1134964但是它没有用,我对 @ tornado.web.stream_body 部分有疑问。我明白了:

 AttributeError: 'module' object has no attribute 'stream_body'

我的配置:

请求== 1.2.3

龙卷风== 3.1.1

1 个答案:

答案 0 :(得分:1)

stream_body要点指的是别人的龙卷风,而不是任何正式版本(如果你想尝试,可以安装gist评论中提到的提交)。目前(截至Tornado 3.1)不支持将流上传到Tornado服务器。