Thanks, Massimo.
Google docs tell me that my app is granted access to the SQL instance by default, as it is in the same project with the Cloud SQL license, so there's nothing to do there. Also, I set a password for the root user in the data base user management menu. The I created two environment variables in app.yaml as proposed by Google.
class GoogleSQLAdapter(UseDatabaseStoredFile, MySQLAdapter):
uploads_in_blob = True
REGEX_URI = re.compile('^(?P<instance>.*)/(?P<db>.*)$')
def clear_cache(self):
ndb.get_context().clear_cache()
def ignore_cache_for(self, entities = None):
entities = entities or []
ndb.get_context().set_cache_policy(lambda key: key.kind() not in entities)
def __init__(self, db, uri='google:sql://realm:domain/database',
pool_size=0, folder=None, db_codec='UTF-8',
credential_decoder=IDENTITY, driver_args={},
adapter_args={}, do_connect=True, after_connection=None):
self.db = db
self.dbengine = "mysql"
self.uri = uri
self.pool_size = pool_size
self.db_codec = db_codec
self._after_connection = after_connection
if do_connect: self.find_driver(adapter_args, uri)
self.folder = folder or pjoin('$HOME',THREAD_LOCAL.folder.split(
os.sep+'applications'+os.sep,1)[1])
ruri = uri.split("://")[1]
m = self.REGEX_URI.match(ruri)
if not m:
raise SyntaxError("Invalid URI string in SQLDB: %s" % self.uri)
instance = credential_decoder(m.group('instance'))
self.dbstring = db = credential_decoder(m.group('db'))
driver_args['instance'] = instance
#KK's addition to attempt fix 2nd gen problem with missing user name and password:
driver_args['user'] = os.environ.get('CLOUDSQL_USER')
driver_args['password'] = os.environ.get('CLOUDSQL_PASSWORD')
if not 'charset' in driver_args:
driver_args['charset'] = 'utf8'
self.createdb = createdb = adapter_args.get('createdb',True)
if not createdb:
driver_args['database'] = db
#KK added this for debug:
print "DEBUG: driver args = " + str(driver_args)
def connector(driver_args=driver_args):
return rdbms.connect(**driver_args)
self.connector = connector
if do_connect: self.reconnect()