Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error connecting Django to Google CloudSQL Postgres database in Google App Engine

I'm evaluating using Google Cloud and Google App Engine for our company's new product. I'm trying to adapt this tutorial to use Postgres instead of MySQL:

https://cloud.google.com/python/django/flexible-environment

While I'm able to successfully connect to the database locally, when I try in production, I get the following 500 error:

OperationalError at /admin/login/
    could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/cloudsql/<project_name_hidden>:us-central1:<database_id_hidden>/.s.PGSQL.5432"?

To connect to Postgres, I made three changes to the sample project. I have this snippet in app.yaml:

beta_settings:
  cloud_sql_instances: <project_name_hidden>:us-central1:<database_id_hidden>

I have this snippet in settings.py:

# [START dbconfig]
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'polls',
        'USER': '<db_user_name_hidden>',
        'PASSWORD': '<db_password_hidden>',
        'PORT': '5432',
    }
}
# In the flexible environment, you connect to CloudSQL using a unix socket.
# Locally, you can use the CloudSQL proxy to proxy a localhost connection
# to the instance
DATABASES['default']['HOST'] = '/cloudsql/<project_name_hidden>:us-central1:<database_id_hidden>'
if os.getenv('GAE_INSTANCE'):
    pass
else:
    DATABASES['default']['HOST'] = '127.0.0.1'
# [END dbconfig]

and have this requirements.py:

Django==1.10.6
#mysqlclient==1.3.10
psycopg2==2.7.1
wheel==0.29.0
gunicorn==19.7.0
like image 219
mathew Avatar asked Mar 16 '17 14:03

mathew


1 Answers

Never mind, seems like Google fixed something on their end and the service is working now. I'm trying to figure out what exactly changed...

like image 65
mathew Avatar answered Sep 29 '22 11:09

mathew