pythonkaggle

manually authenticate kaggle api


One of these combinations should work for setting the account info to download a kaggle dataset. Placing the json file in azure isn't working so was trying this

import kaggle
api=kaggle.KaggleApi()
api.CONFIG_NAME_USER='abc'
api.CONFIG_NAME_KEY='xyz'
api.read_config_environment({"username":"abc","key":"xyz"})
api.authenticate()
api.competition_download_files('dataset_name')

EDIT: This is source and I'be tried setting all of these variables manually

config_data = self.read_config_environment(config_data)

    # Step 2: if credentials were not in env read in configuration file
    if self.CONFIG_NAME_USER not in config_data \
            or self.CONFIG_NAME_KEY not in config_data:
        if os.path.exists(self.config):
            config_data = self.read_config_file(config_data)
        else:
            raise IOError('Could not find {}. Make sure it\'s located in'
                          ' {}. Or use the environment method.'.format(
                              self.config_file, self.config_dir))

Solution

  • Kaggle authenticates automatically at the time you import the kaggle library so you need to set the environment variables before you import it.
    The correct names for the environment variables are KAGGLE_USERNAME and KAGGLE_KEY.

    import os
    
    os.environ['KAGGLE_USERNAME'] = 'username'
    os.environ['KAGGLE_KEY'] = 'key'
    
    from kaggle import api # import the already authenticated API client
    
    api.dataset_download_files('netflix-inc/netflix-prize-data', path='data', unzip=True)