我有请求处理程序:
@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来自请求处理程序模块,但是
必须在别处定义它!
SO传递方法
autofavoritetweettask
到
autofavoritetweet
不起作用?
但为什么大部分时间都是这样:
这个错误是在加载模块时出现的。
我不明白为什么有时所有模块都加载到任务队列中,但有时不是。
谢谢您。
更新1:管理员要求是
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