从第三方应用程序导入视图时,Django 应用程序抛出虚假异常

发布于 2024-10-08 15:53:45 字数 5448 浏览 3 评论 0原文

我正在开发一个 Django 应用程序,当尝试从第三方应用程序(具体来说,Solango)导入模块时,该应用程序偶尔会引发 ViewDoesNotExist 异常。我所说的“偶尔”是指经常令人厌烦,但绝对是少数请求。 Solango 位于应用的 PYTHONPATH 上,可以通过控制台可靠地导入。该错误在本地开发期间也从未发生过,因此可能与服务器设置有关(该应用程序在守护进程模式下使用 Apache + mod_wsgi)。

这是一个堆栈跟踪,显示了管理中发生的错误(尽管它几乎发生在网站的每个页面上):

Traceback:
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root
  445.             return self.index(request)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/contrib/admin/sites.py" in index
  342.             context_instance=template.RequestContext(request)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader.py" in render_to_string
  108.     return t.render(context_instance)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  245.                     return self.nodelist_true.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  255.             return self.nodelist_true.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  372.             url = reverse(self.view_name, args=args, kwargs=kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in reverse
  265.             *args, **kwargs)))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in reverse
  238.         possibilities = self.reverse_dict.getlist(lookup_view)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
  165.                     for name in pattern.reverse_dict:
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
  173.                     lookups.appendlist(pattern.callback, (bits, p_pattern))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_callback
  134.             raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e))

Exception Type: ViewDoesNotExist at /admin/
Exception Value: Could not import solango.views. Error was: cannot import name settings

关于导致问题的原因,或者至少我如何调试它,有什么想法吗?

I'm working on a Django app that occasionally throws a ViewDoesNotExist exception when trying to import modules from a third-party app (Solango, to be specific). By "occasionally", I mean often enough to be annoying, but definitely a minority of requests. Solango is on the app's PYTHONPATH and can be imported reliably through the console. The error also never happens during local development, so maybe it has something to do with the server setup (the app uses Apache + mod_wsgi in daemon mode).

Here's a stack trace showing the error occurring in the admin (although it occurs on pretty much every page on the site):

Traceback:
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root
  445.             return self.index(request)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/contrib/admin/sites.py" in index
  342.             context_instance=template.RequestContext(request)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader.py" in render_to_string
  108.     return t.render(context_instance)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  245.                     return self.nodelist_true.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  255.             return self.nodelist_true.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  372.             url = reverse(self.view_name, args=args, kwargs=kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in reverse
  265.             *args, **kwargs)))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in reverse
  238.         possibilities = self.reverse_dict.getlist(lookup_view)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
  165.                     for name in pattern.reverse_dict:
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
  173.                     lookups.appendlist(pattern.callback, (bits, p_pattern))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_callback
  134.             raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e))

Exception Type: ViewDoesNotExist at /admin/
Exception Value: Could not import solango.views. Error was: cannot import name settings

Any ideas on what's causing the problem, or at least how I can go about debugging it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

GRAY°灰色天空 2024-10-15 15:53:45

您的网络服务器没有文件描述符。重新配置 mod_wsgi 为守护进程模式。

Your web server is out of file descriptors. Reconfigure mod_wsgi for daemon mode.

千年*琉璃梦 2024-10-15 15:53:45

导入的代码可能具有顺序依赖性。这不会出现在开发服务器中,因为预加载了很多不在生产 WSGI 服务器下的内容。

所以最终就像你如何使用 Django 一样。在此期间,您可以尝试以下建议:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

获取 WSGI 脚本文件的替代内容,看看问题是否消失。

You could have order dependencies in what code is imported. This doesn't show up in development servers as a lot of stuff is preloaded which isn't under production WSGI server.

So ultimately it is like how you are using Django. In the interim you can try advice in:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

for alternate content for WSGI script file and see if problem goes away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文