How to Set Up Google Cloud ADC (Application Default Credentials) in Django on PythonAnywhere?

I'm trying to set up Google Cloud's Application Default Credentials (ADC) for my Django project on PythonAnywhere, but I keep encountering the following error:

Error creating story: Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information.

What I've Tried:

  1. Created a Service Account:
    • Created a service account in Google Cloud and downloaded the JSON key file.
    • Stored the file at: /home/footageflow/helloworld2003-754c20cfa98d.json.
  2. Set the GOOGLE_APPLICATION_CREDENTIALS Environment Variable:
    • Added the following to .bashrc
export GOOGLE_APPLICATION_CREDENTIALS="/home/footageflow/helloworld2003-754c20cfa98d.json"  
  1. Tried Programmatic Credentials:
    • Explicitly set the variable in my Django code
import os  
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/home/footageflow/helloworld2003-754c20cfa98d.json"  

  1. Attempted CLI Authentication:
    • Installed the gcloud CLI on PythonAnywhere.
    • Ran gcloud auth application-default login and authenticated successfully. enter code here

Problem: Despite trying all these steps, the error persists when I run the code on PythonAnywhere. The same code works fine locally after authenticating with gcloud.

My Questions:

  1. Is there something specific I need to configure for ADC to work on PythonAnywhere?
  2. Do I need to grant additional permissions to my service account in Google Cloud?
  3. Could the issue be related to how PythonAnywhere handles environment variables or service accounts?

Additional Information:

  • The Django project is running on PythonAnywhere.
  • Locally, the project works perfectly after authentication.

Any help or guidance would be greatly appreciated!

Вернуться на верх