PermanentTaskFailure:加载所有模块时,“模块”对象没有属性错误

时间:2018-08-07 21:09:41

标签: google-app-engine flask

我有请求处理程序:

@app.route('/autofavoritetweet/')
def autofavoritetweet():
  deferred.defer(autofavoritetweettask,twaccount_db.key,_countdown=random.randint(0,60),_retry_options=options)    

传递给任务队列的方法是

def autofavoritetweettask(twaccount_db_key):
   api.create_favorite()

这工作正常,但有时会出现此错误:

X-Appengine-Taskretrycount:0, X-Appengine-Tasketa:1533673734.18604, X-Appengine-Current-Namespace:, X-Appengine-Taskname:72761135380882302641, X-Appengine-Taskexecutioncount:0, X-Appengine-Queuename:default, X-Appengine-Country:ZZ (X-Appengine-Taskretrycount: /base/alloc/tmpfs/dynamic_runtimes/python27/8882c914eb6132e9_unzipped/python27_lib/versions/1/google/appengine/ext/deferred/deferred.py:311)
2018-08-08 05:28:58.460 JST
Successfuly imported extension module "markdown.extensions.extra". (lib.zip/markdown/__init__.py:249)
2018-08-08 05:28:58.466 JST
Successfuly imported extension module "markdown.extensions.smart_strong". (lib.zip/markdown/__init__.py:233)
2018-08-08 05:28:58.467 JST
Successfully loaded extension "markdown.extensions.smart_strong.SmartEmphasisExtension". (lib.zip/markdown/__init__.py:190)
2018-08-08 05:28:58.498 JST
Successfuly imported extension module "markdown.extensions.fenced_code". (lib.zip/markdown/__init__.py:233)
2018-08-08 05:28:58.498 JST
Successfully loaded extension "markdown.extensions.fenced_code.FencedCodeExtension". (lib.zip/markdown/__init__.py:190)
2018-08-08 05:28:58.510 JST
Successfuly imported extension module "markdown.extensions.footnotes". (lib.zip/markdown/__init__.py:233)
2018-08-08 05:28:58.510 JST
Successfully loaded extension "markdown.extensions.footnotes.FootnoteExtension". (lib.zip/markdown/__init__.py:190)
2018-08-08 05:28:58.528 JST
Successfuly imported extension module "markdown.extensions.attr_list". (lib.zip/markdown/__init__.py:233)
2018-08-08 05:28:58.528 JST
Successfully loaded extension "markdown.extensions.attr_list.AttrListExtension". (lib.zip/markdown/__init__.py:190)
2018-08-08 05:28:58.536 JST
Successfuly imported extension module "markdown.extensions.def_list". (lib.zip/markdown/__init__.py:233)
2018-08-08 05:28:58.536 JST
Successfully loaded extension "markdown.extensions.def_list.DefListExtension". (lib.zip/markdown/__init__.py:190)
2018-08-08 05:28:58.545 JST
Successfuly imported extension module "markdown.extensions.tables". (lib.zip/markdown/__init__.py:233)
2018-08-08 05:28:58.545 JST
Successfully loaded extension "markdown.extensions.tables.TableExtension". (lib.zip/markdown/__init__.py:190)
2018-08-08 05:28:58.552 JST
Successfuly imported extension module "markdown.extensions.abbr". (lib.zip/markdown/__init__.py:233)
2018-08-08 05:28:58.552 JST
Successfully loaded extension "markdown.extensions.abbr.AbbrExtension". (lib.zip/markdown/__init__.py:190)
2018-08-08 05:28:58.553 JST
Successfully loaded extension "markdown.extensions.extra.ExtraExtension". (lib.zip/markdown/__init__.py:190)
Permanent failure attempting to execute task (/base/alloc/tmpfs/dynamic_runtimes/python27/8882c914eb6132e9_unzipped/python27_lib/versions/1/google/appengine/ext/deferred/deferred.py:327)
Traceback (most recent call last):
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/8882c914eb6132e9_unzipped/python27_lib/versions/1/google/appengine/ext/deferred/deferred.py", line 318, in post
    self.run_from_request()
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/8882c914eb6132e9_unzipped/python27_lib/versions/1/google/appengine/ext/deferred/deferred.py", line 313, in run_from_request
    run(self.request.body)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/8882c914eb6132e9_unzipped/python27_lib/versions/1/google/appengine/ext/deferred/deferred.py", line 153, in run
    raise PermanentTaskFailure(e)
PermanentTaskFailure: 'module' object has no attribute 'admin_required'

为什么有时会起作用,有时却不起作用? 我的代码没有与admin_required相关的任何内容,所以我不知道发生了什么。

来自Google文档

You can't pass a method defined in the request handler module.
     

上面的最后一点值得特别注意:传递方法   在请求处理程序模块中定义-指定为   app.yaml中的请求处理程序-不起作用。你可以打电话   deferred.defer来自请求处理程序模块,但是功能   传递给它必须在其他地方定义!

因此无法将方法autofavoritetweettask传递到autofavoritetweet吗? 但是为什么它在大多数时间都有效: check log screen capture

仅在加载模块时出现错误。 我不明白为什么有时所有模块都加载到任务队列中,但有时却不加载。

谢谢。 更新1:Admin_require是

def admin_required(f):
  decorator_order_guard(f, 'auth.admin_required')

  @functools.wraps(f)
  def decorated_function(*args, **kwargs):
    if is_logged_in() and current_user_db().admin:
      return f(*args, **kwargs)
    if not is_logged_in() and flask.request.path.startswith('/api/'):
      return flask.abort(401)
    if not is_logged_in():
      return flask.redirect(flask.url_for('signin', next=flask.request.url))
    return flask.abort(403)

  return decorated_function

0 个答案:

没有答案