2012-06-08 80 views
2

我們有一個名爲封裝模型Python的錯誤 - 我隨機(很少)得到這個奇怪的錯誤在GAE

在模型中,我們有一個TopicM模塊定義一個類主題 我們導入了一個名爲GeneralM在模塊中相同的包裹。 有時(很少)我們得到這個錯誤:

可能是什麼原因? 它可以是循環進口嗎? 我們是否應該把東西放在'__init__.py'?

請指教。

(我對冗長的錯誤道歉) - > - > - >

<type 'exceptions.ImportError'> Python 2.7.2: C:\Python27\pythonw.exe 
Fri Jun 08 11:23:46 2012 

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py in _HandleRequest(self=<google.appengine.tools.dev_appserver.DevAppServerRequestHandler instance>) 
    2779   outfile = cStringIO.StringIO() 
    2780   try: 
=> 2781   self._Dispatch(dispatcher, self.rfile, outfile, env_dict) 
    2782   finally: 
    2783   self.module_manager.UpdateModuleFileModificationTimes() 
self = <google.appengine.tools.dev_appserver.DevAppServerRequestHandler instance>, self._Dispatch = <bound method DevAppServerRequestHandler._Dispat...v_appserver.DevAppServerRequestHandler instance>>, dispatcher = <google.appengine.tools.dev_appserver.MatcherDispatcher object>, self.rfile = <socket._fileobject object>, outfile = <cStringIO.StringO object>, env_dict = {'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~greatest-app-ever', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'F1F836CB', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.5', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py in _Dispatch(self=<google.appengine.tools.dev_appserver.DevAppServerRequestHandler instance>, dispatcher=<google.appengine.tools.dev_appserver.MatcherDispatcher object>, socket_infile=<socket._fileobject object>, outfile=<cStringIO.StringO object>, env_dict={'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~greatest-app-ever', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'F1F836CB', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.5', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...}) 
    2667   dispatcher.Dispatch(app_server_request, 
    2668        outfile, 
=> 2669        base_env_dict=env_dict) 
    2670   finally: 
    2671   request_file.close() 
base_env_dict undefined, env_dict = {'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~greatest-app-ever', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'F1F836CB', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.5', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py in Dispatch(self=<google.appengine.tools.dev_appserver.MatcherDispatcher object>, request=<AppServerRequest relative_url: /prof?lectureKey...mp', mode 'rb' at 0x0384A860> force_admin: False>, outfile=<cStringIO.StringO object>, base_env_dict={'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~greatest-app-ever', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'F1F836CB', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.5', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...}) 
    690   forward_request = dispatcher.Dispatch(request, 
    691            outfile, 
=> 692            base_env_dict=base_env_dict) 
    693 
    694   if forward_request: 
base_env_dict = {'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~greatest-app-ever', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'F1F836CB', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.5', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py in Dispatch(self=<google.appengine.tools.dev_appserver.CGIDispatcher object>, request=<AppServerRequest relative_url: /prof?lectureKey...mp', mode 'rb' at 0x0384A860> force_admin: False>, outfile=<cStringIO.StringO object>, base_env_dict={'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~greatest-app-ever', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'F1F836CB', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.5', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...}) 
    1729      memory_file, 
    1730      outfile, 
=> 1731      self._module_dict) 
    1732  finally: 
    1733  logging.root.level = before_level 
self = <google.appengine.tools.dev_appserver.CGIDispatcher object>, self._module_dict = {'Cookie': <module 'Cookie' from 'C:\Python27\lib\Cookie.pyc'>, 'StringIO': <module 'StringIO' from 'C:\Python27\lib\StringIO.pyc'>, 'UserDict': <module 'UserDict' from 'C:\Python27\lib\UserDict.pyc'>, '__builtin__': <module '__builtin__' (built-in)>, '__future__': <module '__future__' from 'C:\Python27\lib\__future__.pyc'>, '__main__': <module 'prof' from 'C:\Current Project\study-wise\src\prof.py'>, '_abcoll': <module '_abcoll' from 'C:\Python27\lib\_abcoll.pyc'>, '_bisect': <module '_bisect' (built-in)>, '_collections': <module '_collections' (built-in)>, '_functools': <module '_functools' (built-in)>, ...} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py in ExecuteCGI(config=<AppInfoExternal error_handlers=None b...one api_version=1 api_config=None >, root_path=r'C:\Current Project\study-wise\src', handler_path='prof.py', cgi_path=r'C:\Current Project\study-wise\src\prof.py', env={'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~greatest-app-ever', 'AUTH_DOMAIN': 'gmail.com', 'CONTENT_LENGTH': '', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'CURRENT_VERSION_ID': '1.1', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE': 'en-us,en;q=0.5', 'HTTP_CACHE_CONTROL': 'max-age=0', ...}, infile=<cStringIO.StringO object>, outfile=<cStringIO.StringO object>, module_dict={'Cookie': <module 'Cookie' from 'C:\Python27\lib\Cookie.pyc'>, 'StringIO': <module 'StringIO' from 'C:\Python27\lib\StringIO.pyc'>, 'UserDict': <module 'UserDict' from 'C:\Python27\lib\UserDict.pyc'>, '__builtin__': <module '__builtin__' (built-in)>, '__future__': <module '__future__' from 'C:\Python27\lib\__future__.pyc'>, '__main__': <module 'prof' from 'C:\Current Project\study-wise\src\prof.py'>, '_abcoll': <module '_abcoll' from 'C:\Python27\lib\_abcoll.pyc'>, '_bisect': <module '_bisect' (built-in)>, '_collections': <module '_collections' (built-in)>, '_functools': <module '_functools' (built-in)>, ...}, exec_script=<function ExecuteOrImportScript>, exec_py27_handler=<function ExecutePy27Handler>) 
    1629   reset_modules = exec_py27_handler(config, handler_path, cgi_path, hook) 
    1630  else: 
=> 1631   reset_modules = exec_script(config, handler_path, cgi_path, hook) 
    1632  except SystemExit, e: 
    1633  logging.debug('CGI exited with status: %s', e) 
reset_modules = True, exec_script = <function ExecuteOrImportScript>, config = <AppInfoExternal error_handlers=None b...one api_version=1 api_config=None >, handler_path = 'prof.py', cgi_path = r'C:\Current Project\study-wise\src\prof.py', hook = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object> 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py in ExecuteOrImportScript(config=<AppInfoExternal error_handlers=None b...one api_version=1 api_config=None >, handler_path='prof.py', cgi_path=r'C:\Current Project\study-wise\src\prof.py', import_hook=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>) 
    1317 
    1318  if module_code: 
=> 1319  exec module_code in script_module.__dict__ 
    1320  else: 
    1321  script_module.main() 
module_code = <code object <module> at 03760E78, file "C:\Current Project\study-wise\src\prof.py", line 2>, script_module = <module 'prof' from 'C:\Current Project\study-wise\src\prof.py'>, script_module.__dict__ = {'__builtins__': {'ArithmeticError': <type 'exceptions.ArithmeticError'>, 'AssertionError': <type 'exceptions.AssertionError'>, 'AttributeError': <type 'exceptions.AttributeError'>, 'BaseException': <type 'exceptions.BaseException'>, 'BufferError': <type 'exceptions.BufferError'>, 'BytesWarning': <type 'exceptions.BytesWarning'>, 'DeprecationWarning': <type 'exceptions.DeprecationWarning'>, 'EOFError': <type 'exceptions.EOFError'>, 'Ellipsis': Ellipsis, 'EnvironmentError': <type 'exceptions.EnvironmentError'>, ...}, '__doc__': None, '__file__': r'C:\Current Project\study-wise\src\prof.py', '__loader__': <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, '__name__': 'prof', '__package__': None, 'run_wsgi_app': <function run_wsgi_app>, 'template': <module 'google.appengine.ext.webapp.template' f...engine\google\appengine\ext\webapp\template.pyc'>, 'webapp': <module 'google.appengine.ext.webapp' from 'D:\P...engine\google\appengine\ext\webapp\__init__.pyc'>} 
C:\Current Project\study-wise\src\prof.py in() 
     3 from google.appengine.ext.webapp.util import run_wsgi_app 
     4 from google.appengine.ext.webapp import template 
=> 5 from model import TopicM 
     6 from model import LectureM 
     7 from model import GeneralM 
model undefined, TopicM undefined 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in Decorate(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, *args=('model.TopicM',), **kwargs={}) 
    674  self._indent_level += 1 
    675  try: 
=> 676  return func(self, *args, **kwargs) 
    677  finally: 
    678  self._indent_level -= 1 
func = <function load_module>, self = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, args = ('model.TopicM',), kwargs = {} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in load_module(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, fullname='model.TopicM') 
    1856   search_path = parent_module.__path__ 
    1857 
=> 1858  return self.FindAndLoadModule(submodule, fullname, search_path) 
    1859 
    1860 @Trace 
self = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, self.FindAndLoadModule = <bound method HardenedModulesHook.Decorate of <g...ppserver_import_hook.HardenedModulesHook object>>, submodule = 'TopicM', fullname = 'model.TopicM', search_path = [r'C:\Current Project\study-wise\src\model', r'C:\Current Project\study-wise\src\model'] 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in Decorate(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, *args=('TopicM', 'model.TopicM', [r'C:\Current Project\study-wise\src\model', r'C:\Current Project\study-wise\src\model']), **kwargs={}) 
    674  self._indent_level += 1 
    675  try: 
=> 676  return func(self, *args, **kwargs) 
    677  finally: 
    678  self._indent_level -= 1 
func = <function FindAndLoadModule>, self = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, args = ('TopicM', 'model.TopicM', [r'C:\Current Project\study-wise\src\model', r'C:\Current Project\study-wise\src\model']), kwargs = {} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in FindAndLoadModule(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, submodule='TopicM', submodule_fullname='model.TopicM', search_path=[r'C:\Current Project\study-wise\src\model', r'C:\Current Project\study-wise\src\model']) 
    1720           source_file, 
    1721           pathname, 
=> 1722           description) 
    1723 
    1724 
description = ('.py', 'U', 1) 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in Decorate(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, *args=('model.TopicM', <closed file 'C:\Current Project\study-wise\src\model\TopicM.py', mode 'U'>, r'C:\Current Project\study-wise\src\model\TopicM.py', ('.py', 'U', 1)), **kwargs={}) 
    674  self._indent_level += 1 
    675  try: 
=> 676  return func(self, *args, **kwargs) 
    677  finally: 
    678  self._indent_level -= 1 
func = <function LoadModuleRestricted>, self = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, args = ('model.TopicM', <closed file 'C:\Current Project\study-wise\src\model\TopicM.py', mode 'U'>, r'C:\Current Project\study-wise\src\model\TopicM.py', ('.py', 'U', 1)), kwargs = {} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in LoadModuleRestricted(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, submodule_fullname='model.TopicM', source_file=<closed file 'C:\Current Project\study-wise\src\model\TopicM.py', mode 'U'>, pathname=r'C:\Current Project\study-wise\src\model\TopicM.py', description=('.py', 'U', 1)) 
    1663          source_file, 
    1664          pathname, 
=> 1665          description) 
    1666  except: 
    1667 
description = ('.py', 'U', 1) 
C:\Current Project\study-wise\src\model\TopicM.py in() 
     2 from google.appengine.ext import db 
=> 3 import GeneralM 
     4 import LectureM 
     5 
     6 def getTopicsByLecture(lecture): 
GeneralM undefined 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in Decorate(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, *args=('model.GeneralM',), **kwargs={}) 
    674  self._indent_level += 1 
    675  try: 
=> 676  return func(self, *args, **kwargs) 
    677  finally: 
    678  self._indent_level -= 1 
func = <function load_module>, self = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, args = ('model.GeneralM',), kwargs = {} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in load_module(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, fullname='model.GeneralM') 
    1856   search_path = parent_module.__path__ 
    1857 
=> 1858  return self.FindAndLoadModule(submodule, fullname, search_path) 
    1859 
    1860 @Trace 
self = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, self.FindAndLoadModule = <bound method HardenedModulesHook.Decorate of <g...ppserver_import_hook.HardenedModulesHook object>>, submodule = 'GeneralM', fullname = 'model.GeneralM', search_path = [r'C:\Current Project\study-wise\src\model', r'C:\Current Project\study-wise\src\model'] 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in Decorate(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, *args=('GeneralM', 'model.GeneralM', [r'C:\Current Project\study-wise\src\model', r'C:\Current Project\study-wise\src\model']), **kwargs={}) 
    674  self._indent_level += 1 
    675  try: 
=> 676  return func(self, *args, **kwargs) 
    677  finally: 
    678  self._indent_level -= 1 
func = <function FindAndLoadModule>, self = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, args = ('GeneralM', 'model.GeneralM', [r'C:\Current Project\study-wise\src\model', r'C:\Current Project\study-wise\src\model']), kwargs = {} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in FindAndLoadModule(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, submodule='GeneralM', submodule_fullname='model.GeneralM', search_path=[r'C:\Current Project\study-wise\src\model', r'C:\Current Project\study-wise\src\model']) 
    1720           source_file, 
    1721           pathname, 
=> 1722           description) 
    1723 
    1724 
description = ('.py', 'U', 1) 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in Decorate(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, *args=('model.GeneralM', <closed file 'C:\Current Project\study-wise\src\model\GeneralM.py', mode 'U'>, r'C:\Current Project\study-wise\src\model\GeneralM.py', ('.py', 'U', 1)), **kwargs={}) 
    674  self._indent_level += 1 
    675  try: 
=> 676  return func(self, *args, **kwargs) 
    677  finally: 
    678  self._indent_level -= 1 
func = <function LoadModuleRestricted>, self = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, args = ('model.GeneralM', <closed file 'C:\Current Project\study-wise\src\model\GeneralM.py', mode 'U'>, r'C:\Current Project\study-wise\src\model\GeneralM.py', ('.py', 'U', 1)), kwargs = {} 
D:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py in LoadModuleRestricted(self=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object>, submodule_fullname='model.GeneralM', source_file=<closed file 'C:\Current Project\study-wise\src\model\GeneralM.py', mode 'U'>, pathname=r'C:\Current Project\study-wise\src\model\GeneralM.py', description=('.py', 'U', 1)) 
    1663          source_file, 
    1664          pathname, 
=> 1665          description) 
    1666  except: 
    1667 
description = ('.py', 'U', 1) 
C:\Current Project\study-wise\src\model\GeneralM.py in() 
     2 from google.appengine.ext import db 
     3 from google.appengine.api import users 
=> 4 from TopicM import Topic 
     5 from LectureM import Lecture 
     6 
TopicM undefined, Topic undefined 

<type 'exceptions.ImportError'>: cannot import name Topic 
     args = ('cannot import name Topic',) 
     message = 'cannot import name Topic' 
+0

現在我突然得到: – zehelvion

+0

zehelvion

回答

1

嘗試將所有可能的進口移動到模塊的底部, 如果您計劃好您的班級關係,那麼這應該可以解決您的問題!

閱讀這真棒回答您的問題拒絕消失: https://stackoverflow.com/a/894885/988434

玩得開心黑客!

0
from model.TopicM import Topic 

嘗試。