简体   繁体   中英

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. I need get this zip file from response. 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?

The response from your second server carry your zip file by byte[].

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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