首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Python-3.6中的“旋风”发送文件

使用Python-3.6中的“旋风”发送文件
EN

Stack Overflow用户
提问于 2021-06-07 12:04:58
回答 2查看 234关注 0票数 0

我试图使用REST、GET和旋风一起发送一个文件,但是每次返回的文件的校验和是不同的。这背后的原因是什么?这些块是否按不正确的顺序返回?

我正在使用curl下载文件。

谢谢你的建议!

代码语言:javascript
复制
async def get(self, filename):
    chunkSize = 1024 * 1024 * 1 # 1 Mib
    with open(filename, 'rb') as f:
        while True:
            chunk = f.read(chunkSize)
            if not chunk:
                break
            try:
                self.write(chunk) # write the chunk to the response
                await self.flush()# send the chunk to the client
            except iostream.StreamClosedError:
                break
            finally:
                del chunk
                await gen.sleep(0.000000001)
    self.finish()

编辑:我尝试下载一个本地文件,发现curl状态被添加到文件的开头。

curl --用户测试-i -X GET http://localhost:8085/download/testfile.dat -output testfile.dat

在不添加连接的wget中工作得更好。

wget --http-user=test -http-passwd=test http://localhost:8085/download/testfile.dat

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-06-14 00:23:09

编辑:我尝试下载一个本地文件,发现curl状态被添加到文件的开头。curl --用户测试-i -X GET http://localhost:8085/download/testfile.dat --输出testfile.dat

这就是curl -i所做的。从手册页:

代码语言:javascript
复制
       -i, --include
              Include the HTTP response headers in the output. The HTTP
              response headers can include things like server name,
              cookies, date of the document, HTTP version and more...

              To view the request headers, consider the -v, --verbose
              option.

从curl命令行中删除-i,它应该像wget命令行一样工作。

票数 2
EN

Stack Overflow用户

发布于 2021-06-07 14:54:31

代码中的问题是,我为REST客户端编写了一些额外的数据,这些数据最终出现在下载的文件中。我还发现curl在下载的文件中添加了一些额外的头,而wget不这样做。试着和-s下面的数据被添加到文件的开头。

代码语言:javascript
复制
HTTP/1.1 200 OK
Server: TornadoServer/4.4.2
Content-Type: text/html; charset=UTF-8
Date: Mon, 07 Jun 2021 14:41:53 GMT
Transfer-Encoding: chunked
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67871304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档