[Python] python download zip file from the request

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    I am using Python version 3.9.5. I am writing a python script to download the zip file from the browser. here is the code. It works fine if I extract all the files from the zip file. But I just want to download the main zip file which contains all the inner files. How do I do that? Zipfile.write() did not work.

    import requests
    import os
    import json
    from robot.api.deco import keyword
    import zipfile, io


    def download_file(url):
    headers= {"Auth": "{abcd}",
    "accept": "*/*",
    "accept-encoding": "gzip;deflate;br" }
    response = requests.request("GET", url, headers = headers)


    filename = os.getcwd()+'/downloads/'

    z = zipfile.ZipFile(io.BytesIO(response.content))

    z.extractall(filename)

    return response.status_code


    This code works absolutely fine but I just want to download the main zip file and not extract files.

    Continue reading...

Compartilhe esta Página