gpt4 book ai didi

python - 使用 Python 3(而非 Python 2)下载时 Zip 文件损坏

转载 作者:太空宇宙 更新时间:2023-11-04 03:13:31 25 4
gpt4 key购买 nike

我正在尝试使用 Python3 下载 zip 文件,但每次文件都已损坏。

我认为以下代码在 Python2 中运行良好,但现在似乎无法在 Python 3 中运行 - P2 和 P3 之间是否存在可能导致 shutil 工作方式出现问题的变化?

    zip_file = requests.get(zip_package_url, headers = request_headers, stream=True)
with open(zip_file_name, 'wb') as out_file:
shutil.copyfileobj(zip_file.raw, out_file)

最佳答案

已解决 - 从请求中获取字节格式,然后保存为字节似乎可行:

    zip_file = requests.get(zip_package_url, headers = request_headers, stream=True).content
with open(zip_file_name, 'wb') as out_file:
out_file.write(zip_file)

关于python - 使用 Python 3(而非 Python 2)下载时 Zip 文件损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37126265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com