Danil Melnikov
Danil Melnikov

Reputation: 316

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?

Upvotes: 0

Views: 454

Answers (2)

Gcode
Gcode

Reputation: 154

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)

Upvotes: 1

Danil Melnikov
Danil Melnikov

Reputation: 316

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)

Upvotes: 0

Related Questions