Google Colab - Not able to import API key file

609 views Asked by At

I have a code in Google Colab which uses a Python package called Atlite, which in turn retrieves data from the Climate Data Store (CDS) through the use of an API key.

When running this code in Python I just need to have the file containing the key saved in a specific folder and then the code runs perfectly fine.

When I try to run the code in Google Colab the following error arises:

**Exception: Missing/incomplete configuration file: /root/.cdsapirc **

I have the file ".cdsapirc" in my computer but when I try to import it to the "/root" folder in Google Colab it just does not get imported. I can import a .py file, but when I try to import the ".cdsapirc" file (which is basically a txt file) it does not work.

Could someone please help me to solve this issue?

Thank you!

Regards,

Sebastian

1

There are 1 answers

1
euronion On BEST ANSWER

If uploading the .cdsapirc file doesn't work, you could try creating it inside Google Colab using a simple Python script:

uid = "<your uid>"
apikey = "<your api-key"

with open("/root/.cdsapirc", "w") as f:
    print("url: https://cds.climate.copernicus.eu/api/v2", file=f)
    print(f"key: {uid}:{apikey}", file=f)

You can get the uid and apikey either from CDS after logging in or you open you local .cdsapirc file and look them up there, see here for more information.

There might be a nicer solution by someone more familiar with Google Colab though.