1

我正在运行一个烧瓶应用程序,大约 5 个月前将所有内容从 Python 2.7 升级到 3。

大多数事情都很顺利,除了这个一直在本地困扰我的事情。我在 MacBook 上,并在 virtualenv 下OSX 10.12.6brew 安装 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'),我将不再收到错误消息,并且一般来说,在应用程序的其余部分中使用请求时我从来没有遇到过问题。


首先,您需要一个id链接标签和单选按钮。我将它设置在inputlabel同时与线input.id = label.htmlFor = rando_id;

rando_id只是一个随机生成的数字,最多 5000 个,前缀为“radio_”。

最后,您在任何时候都没有将单选按钮附加到屏幕上。我将它添加到标签元素label.appendChild(input);

  var rando_id = "radio_" + Math.floor(Math.random() * Math.floor(5000));
  var newCell = document.createElement("td");
  var input = document.createElement("input");
  var label = document.createElement("label");
  input.id = label.htmlFor = rando_id;
  input.setAttribute("type", "radio");
  input.setAttribute("name", "day");
  label.appendChild(document.createTextNode("1"));
  label.appendChild(input);

function next() {
  if (showDate.getMonth() == 11) {
    showDate.setMonth( 0 );
    showDate.setFullYear( showDate.getFullYear()+1 );
  } else {
    showDate.setMonth( showDate.getMonth()+1 );
  }
  document.getElementById("displayingMonth").innerHTML = months[showDate.getMonth()];
  drawTable( showDate );
}


var showDate = new Date();
var months = ["Januari", "Februari", "March", "April", "May", "June",
              "July", "Augusti", "September", "October", "November", "December"];
var weeks = ["Sunday","Monday","Tuseday","Wednesday","Thursday","Friday","Saturday"];

function drawTable(forDate) {
  var daysInMonth = new Date(forDate.getFullYear(),forDate.getMonth()+1,0).getDate();
  var v = c +1;        
  var cellsToDraw = daysInMonth;
  var month = forDate.getMonth()+1;// non-index version of selected Month
  var newdate = forDate.getFullYear() + "-" + month;
  var table = document.getElementById("table");
  table.innerHTML = "";
  for (var r = 0; r < (daysInMonth / 7); r++) {
    var newRow = document.createElement("tr");
    table.appendChild(newRow);
    for (var c = 0; c < 31 && cellsToDraw > 0; c++) {
      var rando_id = "radio_" + Math.floor(Math.random() * Math.floor(5000));
      var newCell = document.createElement("td");
      var input = document.createElement("input");
      var label = document.createElement("label");
      input.id = label.htmlFor = rando_id;
      input.setAttribute("type", "radio");
      input.setAttribute("name", "day");
      label.appendChild(document.createTextNode("1"));
      label.appendChild(input);
      newCell.appendChild(label);
      newRow.appendChild(newCell);
      cellsToDraw--;
    }
  }
}



    document.getElementById("displayingMonth").innerHTML = months[showDate.getMonth()];
    drawTable( showDate );
<table id="table" cellspacing="0" cellpadding="0"   border-collapse="collapse";>
          <input id="newCell"type="hidden"name="day" value="">
  <h1 id="displayingMonth"></h1>

4

1 回答 1

1

我的本地开发设置中的一个错误是我通过烧瓶应用程序为所有 /static 和 /admin/static 提供服务,而不是通过网络服务器(在我的情况下,nginx)提供它们。因此,对于我点击的一些 url,可能有 10 个请求基本上同时进入,Flask 处于调试模式,并且还连接了一个调试器(通过PyCharm)。

当我遇到麻烦以确保所有 '/static' 和 '/admin/static' 从那里得到服务时,而不是通过烧瓶,并且烧瓶每个 url 只收到 1 个请求,这个问题就消失了。

我不会将此标记为答案,因为仍然存在潜在问题,但如果其他人有与我相同的问题,这是针对我的情况的解决方案。

于 2018-03-07T03:17:58.417 回答