简体   繁体   English

Python 请求根据请求下载 zip 文件。

[英]Python requests download zip file on request.post

I have two servers: First server send some files to second server and then get the zip file.我有两台服务器:第一台服务器向第二台服务器发送一些文件,然后获取 zip 文件。 I need get this zip file from response.我需要从响应中获取这个 zip 文件。 My first server:我的第一台服务器:

files = {'file': ...}
ceb_response = requests.post(ceb, files=files)

My second server respond:我的第二台服务器响应:

return HttpResponse(open('db.zip', 'rb'))

I need to save db.zip file in first server, how can I get the file from <Response [200]> and save file locally on first server?我需要在第一台服务器中保存 db.zip 文件,如何从 <Response [200]> 获取文件并将文件本地保存在第一台服务器上?

The response from your second server carry your zip file by byte[].第二台服务器的响应按字节 [] 携带 zip 文件。

You can save the file in the 1st server like:您可以将文件保存在第一台服务器中,例如:

fileName = '/xxx/db.zip' 
with open(fileName, 'wb') as f:
    f.write(ceb_response.content)

I found this answer:我找到了这个答案:

 import io, requests, pyzipper

    r = requests.post(ceb + 'sync', files=files)

    with pyzipper.AESZipFile(io.BytesIO(r.content)) as zf:
        zf.setpassword(b'1111')
        print(zf)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM