Rushiraj Parmar
Rushiraj Parmar

Reputation: 158

Permission denied while downloading dataset from Kaggle API

I am using Google cloud services and I want to download kaggle dataset. I have followed the standard ways for authentication but still, I am getting "Permission denied" error

My approach:

I have tried the following method:

(1) Installing kaggle using pip

(2) placing the kaggle.json file in /.kaggle directory

(3) ''' chmod 600 /home/rushirajparmar23000/.kaggle/kaggle.json '''

(4) ''' echo '{"username":"USERNAME","key":"KEY"}' >/root/.kaggle/kaggle.json '''

error : -bash: /root/.kaggle/kaggle.json: Permission denied

(5) kaggle competitions download -c facebook-recruiting-iii-keyword-extraction

error: raise ValueError('Error: Missing %s in configuration.' % item) ValueError: Error: Missing username in configuration.

Upvotes: 3

Views: 8855

Answers (3)

Matin Zivdar
Matin Zivdar

Reputation: 711

When I wanted to download a dataset, I got this error. (I think it's related to your question)

Traceback (most recent call last):
  File "/home/matin/.local/bin/kaggle", line 5, in <module>
    from kaggle.cli import main
  File "/home/matin/.local/lib/python3.9/site-packages/kaggle/__init__.py", line 19, in <module>
    from kaggle.api.kaggle_api_extended import KaggleApi
  File "/home/matin/.local/lib/python3.9/site-packages/kaggle/api/__init__.py", line 22, in <module>
    from kaggle.api.kaggle_api_extended import KaggleApi
  File "/home/matin/.local/lib/python3.9/site-packages/kaggle/api/kaggle_api_extended.py", line 84, in <module>
    class KaggleApi(KaggleApi):
  File "/home/matin/.local/lib/python3.9/site-packages/kaggle/api/kaggle_api_extended.py", line 102, in KaggleApi
    os.makedirs(config_dir)
  File "/home/matin/miniconda3/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/kaggle.json'

Solution

sudo mkdir /.kaggle
sudo cp kaggle.json /.kaggle
sudo chmod 600 /.kaggle/kaggle.json
sudo chown `whoami`: /.kaggle/kaggle.json

export KAGGLE_CONFIG_DIR='/.kaggle/'

Explanation

In KaggleApi source code, it's trying to find a directory from the environment.

    config_dir = os.environ.get('KAGGLE_CONFIG_DIR') or os.path.join(
        expanduser('~'), '.kaggle')
    if not os.path.exists(config_dir):
        os.makedirs(config_dir)

So if you add KAGGLE_CONFIG_DIR to your environment, it doesn't try to make a directory! If you got ValueError: Error: Missing username in configuration., you should just change the owner by using chown command.

Upvotes: 3

bmarami
bmarami

Reputation: 1

This worked for me

  1. removed the .kaggle directory that was created when installing the kaggle API: rm -r .kaggle/

  2. created a new .kaggle directory in the home directory: mkdir .kaggle

  3. downloaded the kaggle.json file from my kaggle account:

  4. copied the kaggle.json to .kaggle/: cp ~/Downloads/kaggle.json .kaggle/

  5. chmod 600 .kaggle/kaggle.json

Upvotes: 0

Bruno Mello
Bruno Mello

Reputation: 4618

Maybe this discussion in the kaggle forum might answer your question:

https://www.kaggle.com/general/51898

It has a script you can run to do what you want.

Upvotes: 2

Related Questions