我想在app Engine上构建一个应用程序,它使用Cloud SQL作为后端数据库,而不是App engine自己的数据存储工具(它不支持常见的SQL操作,如JOIN)。
Cloud SQL有一个DB-API,因此我一直在寻找一个轻量级的数据抽象层(DAL)来帮助轻松地操作云数据库。一些研究表明,web2py有一个相当整洁的DAL,它与Cloud SQL兼容。
因为我实际上不需要整个全栈web2py框架,所以我将dal.py文件从/gluon文件夹复制到一个简单的测试应用程序的主目录中,并在我的应用程序中包含了这一行:
from dal import DAL, Field
db=DAL('google:sql://myproject:myinstance/mydatabase')然而,在我部署应用程序并尝试运行它之后,这就产生了一个错误。
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 701, in __call__
handler.get(*groups)
File "/base/data/home/apps/jarod-helloworld/2.357593994022416181/helloworld2.py", line 13, in get
db=DAL('google:sql://serangoon213home:rainman001/guestbook')
File "/base/data/home/apps/jarod-helloworld/2.357593994022416181/dal.py", line 5969, in __init__
raise RuntimeError, "Failure to connect, tried %d times:\n%s" % (attempts, tb)
RuntimeError: Failure to connect, tried 5 times:
Traceback (most recent call last):
File "/base/data/home/apps/jarod-helloworld/2.357593994022416181/dal.py", line 5956, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/base/data/home/apps/jarod-helloworld/2.357593994022416181/dal.py", line 3310, in __init__
self.folder = folder or '$HOME/'+thread.folder.split('/applications/',1)[1]
File "/base/python_runtime/python_dist/lib/python2.5/_threading_local.py", line 199, in __getattribute__
return object.__getattribute__(self, name)
AttributeError: 'local' object has no attribute 'folder'它看起来像是由于语句指定的'folder‘属性有一个错误
self.folder = folder or '$HOME/'+thread.folder.split('/applications/',1)[1]有人知道这个属性是做什么的吗?我该如何解决这个问题?
发布于 2012-04-26 19:48:05
文件夹是DAL构造器中的一个参数。它指向存储DB的文件夹(sqlite)。因此,我认为这不是您的问题所在。我会再次检查连接字符串。
从web2py文档中:
The DAL can be used from any Python program simply by doing this:
from gluon import DAL, Field
db = DAL('sqlite://storage.sqlite',folder='path/to/app/databases')
i.e. import the DAL, Field, connect and specify the folder which contains the .table files (the app/databases folder).
To access the data and its attributes we still have to define all the tables we are going to access with db.define_tables(...).
If we just need access to the data but not to the web2py table attributes, we get away without re-defining the tables but simply asking web2py to read the necessary info from the metadata in the .table files:
from gluon import DAL, Field
db = DAL('sqlite://storage.sqlite',folder='path/to/app/databases',
auto_import=True))
This allows us to access any db.table without need to re-define it.https://stackoverflow.com/questions/9766380
复制相似问题