Issue with adding Google API Credential JSON as Environment Variable

Hi all, I am adding my Google Credential JSON as an environment variable for my Render app under the “Environment Variables” section. However I keep receiving the following error, even after escaping all the \n:

File "/opt/render/project/src/.venv/lib/python3.11/site-packages/google/oauth2/service_account.py", line 242, in from_service_account_info
Sep 5 09:50:34 AM signer = _service_account_info.from_dict(
Sep 5 09:50:34 AM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 5 09:50:34 AM File "/opt/render/project/src/.venv/lib/python3.11/site-packages/google/auth/_service_account_info.py", line 47, in from_dict
Sep 5 09:50:34 AM missing = keys_needed.difference(data.keys())
Sep 5 09:50:34 AM ^^^^^^^^^
Sep 5 09:50:34 AMAttributeError: 'str' object has no attribute 'keys'

my KEY: GOOGLE_CREDS_JSON
my VALUE (the JSON file):

{
  "type": "service_account",
  "project_id": "automations-xxx",
  "private_key_id": "xxx",
  "private_key": "-----BEGIN PRIVATE KEY-----\\nxxx-----END PRIVATE KEY-----\\n",
  "client_email": "xxx@xxx.iam.gserviceaccount.com",
  "client_id": "xxx",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/xxx",
  "universe_domain": "googleapis.com"
}

Does anyone know how I can fix this?

Hi there,

You likely need to use a secrets file for this and not an environment variable.

Regards,

Keith
Render Support, UTC+10 :australia:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.