kaggle command fails with google colaboratory
See original GitHub issueExecuting the following command will result in an error. “kaggle.json” is right under google drive. What is the cause?
https://colab.research.google.com/drive/1BhbII5rQTqfxLK0aYusfHReWJpNSm7XD
!pip install kaggle
Collecting kaggle : Successfully installed Unidecode-1.0.22 kaggle-1.4.7.1 python-slugify-1.2.6
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 = "~/.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)
Download 100%
!kaggle competitions list
Traceback (most recent call last): File “/usr/local/bin/kaggle”, line 7, in <module> from kaggle.cli import main File “/usr/local/lib/python3.6/dist-packages/kaggle/init.py”, line 23, in <module> api.authenticate() File “/usr/local/lib/python3.6/dist-packages/kaggle/api/kaggle_api_extended.py”, line 110, in authenticate self._load_config(config_data) File “/usr/local/lib/python3.6/dist-packages/kaggle/api/kaggle_api_extended.py”, line 149, in _load_config raise ValueError(‘Error: Missing %s in configuration.’ % item) ValueError: Error: Missing username in configuration.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Can you try changing filename above to “/root/.kaggle/kaggle.json”?
https://colab.research.google.com/gist/corrieann/7b1e460d3381bf058627bdaa64840122/kaggle-api.ipynb
It’s because the current directory is changed. Use the code below and run the cell:
!mkdir ~/.kaggle
!cp /content/.kaggle/kaggle.json ~/.kaggle/kaggle.json
And also you can goto the parent directory by using the command
cd ..
In colab by default we get ‘\contents’ as the current working directory. I hope this resolves your issue.