Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Method #550

Open
stefanwerleman opened this issue Feb 21, 2024 · 2 comments
Open

Environment Method #550

stefanwerleman opened this issue Feb 21, 2024 · 2 comments

Comments

@stefanwerleman
Copy link

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
Copy link
Contributor

stevemessick commented Jun 11, 2024

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

http://b/353567101

@eirnym
Copy link

eirnym commented Oct 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants