I am struggling to get my Django app connected to the Cloud SQL database 
when deployed to the App Engine Flexible environment. I am using a Flexible 
App Engine instance in europe-west1. Within the same project I have a MySQL 
Second Generation instance. I can connect to the database from my local 
computer and everything works fine. However, once I deploy my Django app, 
it cannot connect to the database. I get the following error:

OperationalError at /api/v01/cron-jobs/process-data-objects/

(2002, "Can't connect to local MySQL server through socket 
'/cloudsql/cm-platform-01:europe-west1:cm-db-develop' (2)")

Request Method: GET
Request URL: http:
//cm-platform-01.appspot.com/api/v01/cron-jobs/process-data-objects/
Django Version: 1.10.4
Exception Type: OperationalError
Exception Value: 

(2002, "Can't connect to local MySQL server through socket 
'/cloudsql/cm-platform-01:europe-west1:cm-db-develop' (2)")

Exception Location: /env/lib/python3.5/site-packages/MySQLdb/connections.py 
in __init__, line 204
Python Executable: /env/bin/python3.5
Python Version: 3.5.2
Python Path: 

['/home/vmagent/app',
 '/env/bin',
 '/env/lib/python35.zip',
 '/env/lib/python3.5',
 '/env/lib/python3.5/plat-linux',
 '/env/lib/python3.5/lib-dynload',
 '/opt/python3.5/lib/python3.5',
 '/opt/python3.5/lib/python3.5/plat-linux',
 '/env/lib/python3.5/site-packages']

Server time: Wed, 12 Apr 2017 12:27:56 +0000

I have been spending my last two days with this, but I could not find a 
solution. Here is my environment:


Google Cloud SDK version: [150.0.0]

requirements.txt

Django==1.10.4
Pillow==3.4.2
mysqlclient==1.3.10
django-cors-headers==2.0.2
djangorestframework==3.5.4
djangorestframework-jwt==1.9.0
django-crispy-forms==1.6.1
django-filter==1.0.1
gunicorn==19.6
google-api-python-client==1.5.5
google-cloud-storage==0.22.0
python-magic==0.4.12




Django database settings:

'default': {
    'ENGINE': 'django.db.backends.mysql',
    'HOST': '/cloudsql/cm-platform-01:europe-west1:cm-db-develop',
    'NAME': 'cm_develop_01',
    'USER': 'cm-django-app',
    'PASSWORD': '[the-password]'
}


app.yaml

# [START runtime]
runtime: custom
env: flex
entrypoint: gunicorn -b :$PORT common.wsgi

beta_settings:
  cloud_sql_instances: cm-platform-01:europe-west1:cm-db-develop

runtime_config:
  python_version: 3
# [END runtime]


Dockerfile

FROM gcr.io/google_appengine/python
LABEL python_version=python3.5
RUN virtualenv --no-download /env -p python3.5

RUN apt-get update && apt-get install -y libmagic-dev

# Set virtualenv environment variables. This is equivalent to running
# source /env/bin/activate
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
ADD requirements.txt /app/
RUN pip install -r requirements.txt
ADD . /app/
CMD exec gunicorn -b :$PORT common.wsgi


Apps are authorized (by default):
<https://lh3.googleusercontent.com/-I9zDMUKbGX4/WO4b3Hs_kkI/AAAAAAABQLQ/ZAFAcwrdOX4VqzvPaJocURHrXoMtEImuQCLcB/s1600/2017-04-12%2B14_20_13-cm-db-d...%2BAccess%2BControl%2B-%2Bcm-platform-01.jpg>

Any help would be appreciated.

Best,
 Tas

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/767210aa-712b-4323-9b32-673aa402ffce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to