连接到谷歌云sql时,Appengine rdbms失败

时间:2012-12-30 21:14:00

标签: google-app-engine google-cloud-sql

我们使用来自appengine的google cloud sql并且从我们的后端实例中经常收到以下错误。

 File "/base/data/home/apps/s~app-prod/140-backend.363823736662468595/users/reports/__init__.py", line 360, in get_document_types
  cursor.execute('SELECT DISTINCT document_type FROM receipt WHERE ho_key=%s AND document_type IS NOT NULL', (str(ho.key())))
File "/python27_runtime/python27_lib/versions/1/google/storage/speckle/python/api/rdbms.py", line 499, in execute
  self._DoExec(request)
File "/python27_runtime/python27_lib/versions/1/google/storage/speckle/python/api/rdbms.py", line 375, in _DoExec
  response = self._conn.MakeRequest('Exec', request)
File "/python27_runtime/python27_lib/versions/1/google/storage/speckle/python/api/rdbms.py", line 873, in MakeRequest
  response = self._MakeRetriableRequest(stub_method, request)
File "/python27_runtime/python27_lib/versions/1/google/storage/speckle/python/api/rdbms.py", line 897, in _MakeRetriableRequest
  response = self.MakeRequestImpl(stub_method, request)
File "/python27_runtime/python27_lib/versions/1/google/storage/speckle/python/api/rdbms_apiproxy.py", line 68, in MakeRequestImpl
  raise OperationalError('could not connect: ' + str(e))

OperationalError:无法连接:ApplicationError:1002

有没有其他人有这方面的经验?

由于

1 个答案:

答案 0 :(得分:1)

此错误和堆栈跟踪表明您使用的是旧版本且已弃用的google.appengine.api.rdbms界面。

您应该将其替换为MySQLdb模块,该模块被记录为Python中connect to Cloud SQL from App Engine的最佳方式。因为两个接口都符合PEP 249,所以它应该是替代品。如上面GAE上的链接所述,您需要使用MySQLdb.connect(unix_socket="/cloudsql/project:instance", ...)创建连接。