You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

构建石头剪刀布手势图像检测ANN时,Google Drive Zip文件解压触发BadZipFile错误的求助

解决BadZipFile错误:Google Drive链接下载问题

嘿,我一眼就揪出问题啦——你用的Google Drive链接是网页预览地址,不是直接下载文件的链接!当你用wget请求这个地址时,下载下来的其实是Google Drive的预览页面HTML,根本不是真正的zip文件,自然会触发BadZipFile错误。

解决步骤:

  1. 替换Google Drive链接为直接下载格式
    把原来的预览链接:

    https://drive.google.com/file/d/1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59/view?usp=sharing
    

    替换成直接下载链接(提取文件ID 1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59,套入以下格式):

    https://drive.google.com/uc?export=download&id=1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59
    
  2. 修改后的完整代码

    import tensorflow as tf
    !wget --no-check-certificate \
    https://drive.google.com/uc?export=download&id=1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59 \
    -O /tmp/rockpaperscissors.zip
    import zipfile,os
    local_zip = '/tmp/rockpaperscissors.zip'
    zip_ref = zipfile.ZipFile(local_zip, 'r')
    zip_ref.extractall('/tmp')
    zip_ref.close()
    base_dir = '/tmp/image'
    train_dir = os.path.join(base_dir, 'train')
    validation_dir = os.path.join(base_dir, 'val')
    

额外提示:

如果你的zip文件超过100MB,Google Drive可能会弹出验证页面,这时候可以用下面的命令自动处理验证:

!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1zBasc3iGhJwCoCvZngcySO-Zxv1Mle59" -O /tmp/rockpaperscissors.zip && rm -rf /tmp/cookies.txt

不过你的这个文件应该不大,直接用第一种修改后的链接就足够啦。

内容的提问来源于stack exchange,提问作者Aya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 13:12:30