首页 > 代码库 > ImportError: No module named app_factory

ImportError: No module named app_factory

ImportError: No module named app_factory

在运行python的一个wsgi相关的程序时,出现下列错误:

cast503@cast503-OptiPlex-7010:~/python$ python wsgi_paste.py

Traceback (most recent call last):

  File "wsgi_paste.py", line 13, in <module>

    wsgi_app = loadapp(‘config:‘+ini_path)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 247, in loadapp

    return loadobj(APP, uri, name=name, **kw)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 271, in loadobj

    global_conf=global_conf)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 296, in loadcontext

    global_conf=global_conf)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 320, in _loadconfig

    return loader.get_context(object_type, name, global_conf)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 458, in get_context

    section)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 517, in _context_from_explicit

    value = import_string(found_expr)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 22, in import_string

    return pkg_resources.EntryPoint.parse("x=" + s).load(False)

  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1989, in load

    entry = __import__(self.module_name, globals(),globals(), [‘__name__‘])

  File "/home/cast503/python/wsgi_paste.py", line 13, in <module>

    wsgi_app = loadapp(‘config:‘+ini_path)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 247, in loadapp

    return loadobj(APP, uri, name=name, **kw)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 271, in loadobj

    global_conf=global_conf)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 296, in loadcontext

    global_conf=global_conf)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 320, in _loadconfig

    return loader.get_context(object_type, name, global_conf)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 458, in get_context

    section)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 517, in _context_from_explicit

    value = import_string(found_expr)

  File "/usr/lib/python2.7/dist-packages/paste/deploy/loadwsgi.py", line 22, in import_string

    return pkg_resources.EntryPoint.parse("x=" + s).load(False)

  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1989, in load

    entry = __import__(self.module_name, globals(),globals(), [‘__name__‘])

ImportError: No module named app_factory

根据错误提示一直在网上搜app_factory模块,没有找到,最后仔细查看代码,发现在项目配置文件api-paste.ini中将“:”写成了“.”。

正确配置应该是:

[app:hello]

paste.app_factory = app:app_factory

错误配置:

[app:hello]

paste.app_factory = app.app_factory


ImportError: No module named app_factory