mardi 28 juin 2016

GAE Python - OperationalError: (2013, 'Lost connection to MySQL server during query')

I've been trying to connect to ClouSQL using Flexible Environments (vm:true)

but when I upload my app using:

gcloud preview app deploy --version MYVERSION

An error is thrown:

OperationalError: (2013, 'Lost connection to MySQL server during query')

I found out that it might be because the query is too large but I think that's not the case because it works locally and on production when I wans't using flexible environments with MySQLdb.

My code:

import os
import logging
import pymysql

class MySQL(object):
    '''
    classdocs
    '''
    # TO INSTALL LOCAL DB: http://stackoverflow.com/questions/30893734/no-module-named-mysql-google-app-engine-django


    @classmethod
    def getConnection(cls):
        # When running on Google App Engine, use the special unix socket
        # to connect to Cloud SQL.
        if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
            logging.debug('PROJECT [%s], INSTANCE[%s] - USER [%s] - PASS [%s], SCHEMA [%s]',
                          os.getenv('CLOUDSQL_PROJECT'),
                          os.getenv('CLOUDSQL_INSTANCE'),
                          os.getenv('CLOUDSQL_USER'),
                          os.getenv('CLOUDSQL_PASS'),
                          os.getenv('CLOUDSQL_SCHEMA'))

            db = pymysql.connect(unix_socket='/cloudsql/APP:REGION:INSTANCENAME')
                    #os.getenv('CLOUDSQL_PROJECT'),
                    #os.getenv('CLOUDSQL_INSTANCE')), 
                    #user=os.getenv('CLOUDSQL_USER'),
                    #passwd=os.getenv('CLOUDSQL_PASS'),  
                    #db=os.getenv('CLOUDSQL_SCHEMA'))
        # When running locally, you can either connect to a local running
        # MySQL instance, or connect to your Cloud SQL instance over TCP.
        else:
            db = pymysql.connect(host=os.getenv('DBDEV_HOST'), user=os.getenv('DBDEV_USER'), 
                                 passwd=os.getenv('DBDEV_PASS', ''), db=os.getenv('DBDEV_SCHEMA'))

        return db

Any thoughts on this?

Thanks!

Aucun commentaire:

Enregistrer un commentaire