0

我正在为 Google App Engine 写作,我的本地测试出现以下错误:

-->  --> -->

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3185, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3128, in _Dispatch
    base_env_dict=env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 515, in Dispatch
    base_env_dict=base_env_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2387, in Dispatch
    self._module_dict)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2297, in ExecuteCGI
    reset_modules = exec_script(handler_path, cgi_path, hook)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2193, in ExecuteOrImportScript
    exec module_code in script_module.__dict__
  File "C:\Users\Chris Reade\Documents\SI 182\Final\geneticsalesman\Final.py", line 7, in <module>
    from pyevolve import DBAdapters
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1922, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1824, in FindAndLoadModule
    description)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1775, in LoadModuleRestricted
    description)
  File "C:\Users\Chris Reade\Documents\SI 182\Final\geneticsalesman\pyevolve\DBAdapters.py", line 21, in <module>
    import sqlite3
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1922, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1824, in FindAndLoadModule
    description)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1775, in LoadModuleRestricted
    description)
  File "C:\Python26\lib\sqlite3\__init__.py", line 24, in <module>
    from dbapi2 import *
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1922, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1824, in FindAndLoadModule
    description)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1272, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1775, in LoadModuleRestricted
    description)
  File "C:\Python26\lib\sqlite3\dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

我的 python 方向有一个用于 sqlite3 的 lib 文件,但我不知道为什么它找不到它。任何帮助将不胜感激。

4

2 回答 2

1

App Engine SDK 会尽力为您提供在真正的App Engine(在 Google 的服务器上)可能会失败的任何模块导入错误。后者不支持 SQlite,因此给您错误只是 SDK 的一种很好的说法,即“您将无法在真正的 Google App Engine 服务器上部署此代码”!

于 2010-04-19T05:39:48.670 回答
0

当一个人第一次想使用 sqlite3 时,应用引擎会尝试引发错误。发生这种情况并不是因为 App 引擎(本地)不允许使用 sqlite3 作为备用数据库,而是因为生产级别不支持 sqlite3 。所以 App 引擎正在做它的基础来阻止你使用 sqlite3,这样你就不会错误地使用 sqlite3 部署应用程序。
因此,要在本地 App Engine 中使用 sqlite3,您需要将 sqlite3 列入白名单,如下所示:

转到C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\python\runtime\sandbox.py
打开文件,你会发现一个常量变量 _WHITE_LIST_C_MODULES 声明为:

  _WHITE_LIST_C_MODULES = [
        'array',
        '_ast',
        'binascii',
        '_bisect',
         .
         .
         .,
]

然后添加 sqlite3 如下:

  _WHITE_LIST_C_MODULES = [
                'array',
                '_ast',
                'binascii',
                '_bisect',
                 .
                 .
                 .,
                _sqlite3,
        ]

我希望这对你有用。

于 2019-05-27T13:30:04.217 回答