手动验证kaggle api

问题描述 投票:0回答:1

这些组合之一应该适用于设置帐户信息以下载 Kaggle 数据集。将 json 文件放入 azure 中不起作用,所以正在尝试这个

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')

编辑: 这是源代码,我尝试手动设置所有这些变量

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))
python kaggle
1个回答
0
投票

Kaggle 在您导入 Kaggle 库时自动进行身份验证,因此您需要在导入之前设置环境变量。
此外,变量的正确名称是

KAGGLE_USERNAME
KAGGLE_KEY

import os

os.environ['KAGGLE_USERNAME'] = 'username'
os.environ['KAGGLE_KEY'] = 'key'

from kaggle.api import KaggleApi
© www.soinside.com 2019 - 2024. All rights reserved.