Skip to content
Advertisement

How do I read Google API credentials from a TOML file with Python?

I’m trying to pull some data using the Google Sheets Api. This is the beginning of the code:

JavaScript

In the tutorial I am referring to, this is what the author says about the JSON_DATA object:

Note: the ‘JSON_DATA’ variable in the python code is a Netlify build environment variable that I set with JSON format Google API credential information to keep my secret stuff out of the script.

My netlify.toml, which contains the build environment variable has this:

JavaScript

I know that to include my credentials downloaded from Google (in a JSON file), I have to put this in the netlify.toml:

JavaScript

but how do I read in these credentials for the Python code? That line seems to indicated that it wants a JSON file only.

Advertisement

Answer

Okay, so you need to copy paste the contents of the json key file in the actual environment variable itself:

JSON_DATA = '{"key":"secret"}'

Not the most straight forward way, but it works.

In order to maintain sanity I would use the web interface to work with those variables.

https://docs.netlify.com/configure-builds/environment-variables/

The first line parses whatever is in the environment variable to a dict. There’s no need in this case to parse the toml itself, as it has already been parsed for you.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement