我正在运行一个烧瓶应用程序,大约 5 个月前将所有内容从 Python 2.7 升级到 3。
大多数事情都很顺利,除了这个一直在本地困扰我的事情。我在 MacBook 上,并在 virtualenv 下OSX 10.12.6
brew 安装 Python 。3.6.3
当一个请求来自一个看似有多个静态请求(主要是 .css、.js 和图像文件)的页面时,我似乎能够在我的代码中任何地方使用生成器的任何地方得到这个错误。
一些例子(请求是一个flask.request
对象):
检查路径是否以“/admin/static”(我的代码)的“/static”开头的地方,
any(request.path.startswith(k) for k in self._static_paths)
.
Exception ignored in: <generator object CustomPrincipal._is_static_route.<locals>.<genexpr> at 0x11450f3b8>
Traceback (most recent call last):
File "/Developer/repos/git/betapilibs/lbbsports/flask_monkeypatches.py", line 22, in <genexpr>
any(_checker(request.path, k) for k in self._static_paths)
SystemError: error return without exception set
如果 url 路径受到限制,请检查登录用户是否具有适当的权限/角色,
return role in (role.name for role in self.roles)
.
Exception ignored in: <generator object UserMixin.has_role.<locals>.<genexpr> at 0x1155a7e08>
Traceback (most recent call last):
File "/Developer/virtualenvs/lbb3/lib/python3.6/site-packages/flask_security/core.py", line 386, in <genexpr>
SystemError: error return without exception set
一段自定义代码,以确保其“子”帐户 ID 有效,
(not any(ident == account_id for ident in account_ids))
.
Exception ignored in: <generator object CustomSession.get_set_accounts.<locals>.<genexpr> at 0x115ff4fc0>
Traceback (most recent call last):
File "/Developer/customflask/flasklogin.py", line 168, in <genexpr>
SystemError: error return without exception set
现在,系统似乎没有任何问题,我只是收到这些错误消息,而且并非始终如一,只是有时。如果我在报告这些错误发生的任何地方设置断点,它们就不会再出错了。
如果我在第一个示例中执行类似的操作,将其拆分为request.path.startswith('/static') or request.path.startswith('/admin/static')
,我将不再收到错误消息,并且一般来说,在应用程序的其余部分中使用请求时我从来没有遇到过问题。