Error while importing Kaggle dataset on Colab

后端 未结 7 2107
长发绾君心
长发绾君心 2020-12-30 12:41

When executing the following lines,

!pip install kaggle
!kaggle competitions download -c dogs-vs-cats -p /content/

I got the following erro

7条回答
  •  不知归路
    2020-12-30 13:22

    It suddenly stopped working here as well. Apparently, the kaggle api was not searching the kaggle.json file in the correct place. Since I was using the kaggle api inside a colab notebook, I was importing the kaggle.json like this:

    from googleapiclient.discovery import build
    import io, os
    from googleapiclient.http import MediaIoBaseDownload
    from google.colab import auth
    
    auth.authenticate_user()
    
    drive_service = build('drive', 'v3')
    results = drive_service.files().list(
            q="name = 'kaggle.json'", fields="files(id)").execute()
    kaggle_api_key = results.get('files', [])
    
    filename = "/content/.kaggle/kaggle.json"
    os.makedirs(os.path.dirname(filename), exist_ok=True)
    
    request = drive_service.files().get_media(fileId=kaggle_api_key[0]['id'])
    fh = io.FileIO(filename, 'wb')
    downloader = MediaIoBaseDownload(fh, request)
    done = False
    while done is False:
        status, done = downloader.next_chunk()
        print("Download %d%%." % int(status.progress() * 100))
    os.chmod(filename, 600)
    

    It worked just fine. But now, the kaggle api searches the kaggle.json in this location:

    ~/.kaggle/kaggle.json
    

    So, I just had to move/copy the file I downloaded to the right place:

    !mkdir ~/.kaggle
    !cp /content/.kaggle/kaggle.json ~/.kaggle/kaggle.json
    

    And it started working again.

提交回复
热议问题