kaggle-api: kaggle api returns 401 - Unauthorized
I can’t download kaggle data via kaggle api, either on local and on google colab. I can download data on kaggle GUI, which means I successfully enrolled in the competition.
I followed the procedure on https://github.com/Kaggle/kaggle-api to use kaggle api.
Here are information on my environment.
ls /Users/.kaggle/
# ls /Users/.kaggle/
# kaggle.json
ls -l /Users/.kaggle/
# total 8
# -rw-r--r--@ 1 root admin 64 6 26 18:59 kaggle.json
kaggle competitions list
# 401 - Unauthorized
kaggle competitions download -c global-wheat-detection
# 401 - Unauthorized
pip show kaggle
# Name: kaggle
# Version: 1.5.6
# Summary: Kaggle API
# Home-page: https://github.com/Kaggle/kaggle-api
# Author: Kaggle
# Author-email: support@kaggle.com
# License: Apache 2.0
# Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
# Requires: python-dateutil, requests, python-slugify, six, tqdm, certifi, urllib3
# Required-by:
I thought the api token was not made correctly, so I made them all expire and made a new token again, but it did not work.
I appreciate if anyone help me out.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 34
I ran into the same problem, but after creating a new Kaggle Token, the problem was fixed!
I overcame this issue by deleteing the kagge.json file and replacing it with a new one downloaded from kaggle. Its the file that goes exacty at root/.kaggle/kaggle.json
I’ve also run into this issue!
Ran into this problem as well, even when creating a new Kaggle Token and/or expiring all tokens before I’m still getting 401 Unauthorized.
issue resolved for me when i took new api token and expired all previous ones and downloaded json file again from kaggle by deleting old json file. It works
I had uploaded the JSON file into colab already while working, so even after creating a new token since I forgot to clear all the outputs from the kernel it was still showing an error. If anyone’s working in google colab they should do a factory reset before uploading a new JSON file.
So why is this closed? The code is definitely broken. If Kaggle cannot generate tokens, or have problems with their request validation or whatever else the problem is, they need to know about it / fix it.
Why close this issue if nothing was fixed?
Okay, strangely enough, it started to work, my bad.
FYI, try the EXPORT Command, it will precendence over the kaggle.json file. This was how it started to work in mine. Thanks
What worked for me was creating a token without expiring the old one(s). Based on the toast notifications in the Kaggle web app, it looked like clicking “Expire API Token” followed by “Create New API Token” actually resulted in the new token getting created and then immediately being expired. When I clicked “Create” without first “Expire”, the newly generated token worked as expected.
After renewing your API if you still have issue, make sure your json file name is kaggle.json and your code is the same as below.
You can check if the following in ~ / .bashrc are the same as kaggle.json
Issue for me was that I set the kaggle API key using parenthesis ("). Should (obivously) be without it…