Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 导入web2py';s DAL将与应用程序引擎上的Google Cloud SQL一起使用_Python_Google App Engine_Web2py - Fatal编程技术网

Python 导入web2py';s DAL将与应用程序引擎上的Google Cloud SQL一起使用

Python 导入web2py';s DAL将与应用程序引擎上的Google Cloud SQL一起使用,python,google-app-engine,web2py,Python,Google App Engine,Web2py,我想在AppEngine上构建一个应用程序,它使用云SQL作为后端数据库,而不是AppEngine自己的数据存储设施(不支持常见的SQL操作,如JOIN) 云SQL有一个DB-API,因此我正在寻找一个轻量级数据抽象层(DAL)来帮助轻松地操作云数据库。一项小小的研究表明web2py有一个非常整洁的DAL,它与云SQL兼容 因为我实际上并不需要整个完整的web2py框架,所以我将dal.py文件从/glion文件夹复制到了一个简单测试应用程序的主目录中,并在我的应用程序中包含了这一行: from

我想在AppEngine上构建一个应用程序,它使用云SQL作为后端数据库,而不是AppEngine自己的数据存储设施(不支持常见的SQL操作,如JOIN)

云SQL有一个DB-API,因此我正在寻找一个轻量级数据抽象层(DAL)来帮助轻松地操作云数据库。一项小小的研究表明web2py有一个非常整洁的DAL,它与云SQL兼容

因为我实际上并不需要整个完整的web2py框架,所以我将dal.py文件从/glion文件夹复制到了一个简单测试应用程序的主目录中,并在我的应用程序中包含了这一行:

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]

是否有人知道此属性的作用以及如何解决此问题?

文件夹是DAL构造函数中的一个参数。它指向存储DBs(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.