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

如何修复Colab上传自定义数据集时的HttpError 404问题

Fixing PyDrive HttpError 404 When Accessing Google Drive Files in Colab

Looks like you hit a common PyDrive gotcha in Google Colab—let’s break down the issue and fix it right away:

The Root Cause

Your 404 error occurs because you’re passing the full Google Drive share URL to drive.CreateFile({'id': zip_id}), but PyDrive only expects the unique file ID, not the entire link. The error message even calls this out clearly: it’s trying to look up a file with the ID https://drive.google.com/open?id=1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW, which is obviously not a valid file ID.

Step-by-Step Fix

  1. Extract the actual file ID
    From your share link https://drive.google.com/open?id=1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW, the valid file ID is the string directly after id=—that's 1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW.

  2. Update your code’s zip_id line
    Replace the full URL with just the extracted file ID:

    zip_id = '1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW'
    
  3. Full corrected code
    Here’s the complete working version of your snippet:

    !pip install -U -q PyDrive
    # Insert your file ID
    # Get it by generating a share URL for the file
    # An example : https://drive.google.com/file/d/1iz5JmTB4YcBvO7amj3Sy2_scSeAsN4gd/view?usp=sharing
    zip_id = '1RqLx88tx2FCV0Z3CHsqVtx7S3_ffE-UW'
    from pydrive.auth import GoogleAuth
    from pydrive.drive import GoogleDrive
    from google.colab import auth
    from oauth2client.client import GoogleCredentials
    import zipfile, os
    # 1. Authenticate and create the PyDrive client.
    auth.authenticate_user()
    gauth = GoogleAuth()
    gauth.credentials = GoogleCredentials.get_application_default()
    drive = GoogleDrive(gauth)
    if not os.path.exists('MODEL'):
        os.makedirs('MODEL')
    # 2. Download Zip
    print ("Downloading zip file")
    myzip = drive.CreateFile({'id': zip_id})
    myzip.GetContentFile('model.zip')
    # 3. Unzip
    print ("Uncompressing zip file")
    zip_ref = zipfile.ZipFile('model.zip', 'r')
    zip_ref.extractall('MODEL/')
    zip_ref.close()
    

Extra Tips

  • Ensure your Google Drive file is set to publicly accessible (or shared with the Colab service account if using restricted access). If it’s private, you’ll run into permission errors even with the correct ID.
  • For files stored in shared folders, you may need to traverse the folder structure using its ID, but for single uploaded files, the direct file ID method works flawlessly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:47:54