Kaggle / kaggle-api

Official Kaggle API
Apache License 2.0
6.13k stars 1.08k forks source link

kaggle api returns 401 - Unauthorized #279

Closed mhiro216 closed 3 years ago

mhiro216 commented 4 years ago

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.

AlinaWithAFace commented 4 years ago

I've also run into this issue!

chizuchizu commented 3 years ago

I ran into the same problem, but after creating a new Kaggle Token, the problem was fixed!

Quoding commented 3 years ago

I ran into the same problem, but after creating a new Kaggle Token, the problem was fixed!

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.

ChrisRichardMiles commented 3 years ago

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

mhiro216 commented 3 years ago

Thank you all. I resolved this issue with you all's process.

abdulqadircp commented 3 years ago

I overcome this problem by creating a new API token and then replaced that with the older one.

pepetikesavasiddhardha commented 3 years ago

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

aeikay commented 3 years ago

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.

cgebbe commented 2 years ago

Issue for me was that I set the kaggle API key using parenthesis ("). Should (obivously) be without it...

%env KAGGLE_KEY="1234...567890"
deep-woods commented 2 years ago

Hi. I ran into the same issue while following this guideline in google colab: https://www.kaggle.com/general/74235

I tried @Chizuchizu's tip, and it worked.

1) Factory reset runtime 2) Expire and redownload a new API.

Thanks everyone!

La-fe commented 2 years ago

You can check if the following in ~ / .bashrc are the same as kaggle.json

export KAGGLE_USERNAME=datadinosaur
export KAGGLE_KEY=xxxxxxxxxxxxxx
Abdelrahman3ly commented 2 years ago

I still have this problem , please help me

JanSurft commented 2 years ago

If your are on a jupyter instance: For me it helped to restart the kernel after updating the API Key. That's what "Factory reset runtime" was for @deep-woods.

wvxvw commented 2 years ago

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?

aaronjoseph commented 2 years ago

Facing this issue here as well.

Tried to expire the tokens and run it (saved the json in ~/.kaggle/kaggle.json & also tried to do in bashrc with the export command + source command)

Still no luck. Suprising.

Is there any command, by which kaggle user json config can be re-initialized ?

bi1yeu commented 2 years ago

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.

NishaniKasineshan commented 2 years ago

I ran into the same problem today.@bi1yeu tip worked for me.Thank you.

Padmanabhan100 commented 2 years ago

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

Thanks a lot man, it worked!!

aaronjoseph commented 2 years ago

I am facing this issue on my my system. Have done the following

  1. Created ~/kaggle/kaggle.json
  2. chmod 600 for the same
  3. Installed kaggle via pip
  4. And tried the kaggle commands
  5. Yet, failing with 401 error
  6. Tried running with updated credentials, and still face the same issue
aaronjoseph commented 2 years ago

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

DonaBiswas45 commented 2 years ago

how did u apply EXPORT, can you write th code for me

Code2147483647 commented 2 years ago

Same problem here. I repeat expire all token and then create new token but always 401 unauthorized...

aaronjoseph commented 2 years ago

So, do check your file manually as well. Which is placed at ~/kaggle/kaggle.json. Quite often the export commands don't update it.

aaronjoseph commented 2 years ago

how did u apply EXPORT, can you write th code for me

It's a Linux command to create a variable and assign it a value

alghenab commented 2 years ago

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.

! mkdir ~/.kaggle
! cp kaggle.json ~/.kaggle/kaggle.json
! chmod 600 ~/.kaggle/kaggle.json
! kaggle datasets list
DilpatRai commented 2 years ago

I am facing the same issue (ApiException: (401)) while downloading the dataset from Kaggle I gave the right credentials but still it is showing the same issue

AngelikaAnnemarieKreutzer commented 1 year ago

Ich habe das gleiche Problem (ApiException: (401)) beim Herunterladen des Datensatzes von Kaggle . Ich habe die richtigen Anmeldeinformationen angegeben, aber es zeigt immer noch das gleiche Problem

Vorher war alles in Ordnung. Nur seit heute habe ich das gleiche Problem wie du.

slives-lab commented 1 year ago

All solutions described above don't work. The only solution is to manually download. Not sure why kaggle can't fix this issue: 401 - Unauthorized

Fumeng-Yang commented 1 year ago

I finally resolved this problem by running sudo kaggle ... (after KAGGLE_USERNAME is set). I think it is because I am not using the admin account and chmod 600 only gives permission to the admin.

The-EleetCoder commented 1 year ago

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

yes it worked!

pault-tech commented 1 year ago

In my case the issue was how kaggle cli was installed.

Saw this error after running:

pip install kaggle

but fixed after running:

pip uninstall kaggle pip install --user kaggle (restart shell)

So the issue was actually which user/where the home directory and path to ~/.kaggle/kaggle.json was.

JAYANTHNITW commented 1 year ago

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 fixed my error with your suggestion thank you for helping the community

kietna1809 commented 1 year ago

I fix by reopen the terminal