Kaggle / kaggle-api

Official Kaggle API
Apache License 2.0
6.29k stars 1.1k forks source link

Environment Method #550

Open stefanwerleman opened 9 months ago

stefanwerleman commented 9 months ago

This is for the environment method mentioned in here:

IOError: Could not find kaggle.json. Make sure it's located in /root/.kaggle. Or use the environment method.

I read your logic for reading environment variables in case ~/.kaggle/kaggle.json does not exist. I suggest you first load the environments variable using python-dotenv before using os.environ to extract the variable names that start with KAGGLE_.

The moment someone imports kaggle in their project, your __init__.py script is immediately executed, which, in turn, attempts to read the environment variables before the .env is even loaded. This means the line if key.startwith("KAGGLE_"): in theread_config_environment() method will always return False even if the developer already has an .env file with the correct varaibles.

Here's is a snippet of my suggestion for /kaggle/__init_.py:

# coding=utf-8
import dotenv

# Load environment variables for the read_config_environment() method
dotenv.load_dotenv()

from __future__ import absolute_import
from kaggle.api.kaggle_api_extended import KaggleApi
from kaggle.api_client import ApiClient

api = KaggleApi(ApiClient())
api.authenticate()
stevemessick commented 5 months ago

Thanks for the suggestion! I filed an internal tracking issue and plan to implement this during our next fixit.

http://b/353567101

eirnym commented 1 month ago

@stefanwerleman can you bring any news on that? the issue is really annoying