簡體   English   中英

Python 請求根據請求下載 zip 文件。

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

我有兩台服務器:第一台服務器向第二台服務器發送一些文件,然后獲取 zip 文件。 我需要從響應中獲取這個 zip 文件。 我的第一台服務器:

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

我的第二台服務器響應:

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

我需要在第一台服務器中保存 db.zip 文件,如何從 <Response [200]> 獲取文件並將文件本地保存在第一台服務器上?

第二台服務器的響應按字節 [] 攜帶 zip 文件。

您可以將文件保存在第一台服務器中,例如:

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

我找到了這個答案:

 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