我正在运行一个烧瓶应用程序,大约5个月前从Python 2.7升级到3。
大多数事情已经变得足够顺利了,除了这个一直在当地烦扰我的事情。我在OSX 10.12.6
上使用MacBook,在virtualenv下使用Python 3.6.3
进行brew安装。
当一个请求来自一个看似有多个静态请求(主要是.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')
,我不再收到错误消息,并且一般来说,我在应用程序的其余部分中使用请求时从未遇到任何问题。
在我的本地开发设置中出错的一点是我通过flask应用程序服务所有/ static和/ admin / static,而不是通过web服务器(在我的情况下,nginx
)提供它们。因此,对于我正在尝试的一些网址,可能有10个请求基本上同时进入,Flask处于调试模式,并且调试器也连接(通过PyCharm
)。
当我经历麻烦以确保从那里获得所有'/ static'和'/ admin / static'而不是通过烧瓶,并且烧瓶每个网址只获得1个请求时,这个问题就消失了。
我不会将此标记为答案,因为仍存在潜在问题,但如果其他人遇到与我相同的问题,这是我的情况的解决方案。