google-app-engine - PermanentTaskFailure:加载所有模块时,“模块”对象没有属性错误
问题描述
我有请求处理程序:
@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
,所以我无法弄清楚发生了什么。
来自谷歌文档
You can't pass a method defined in the request handler module.
上面的最后一点值得特别注意:传递请求处理程序模块中定义的方法 - app.yaml 中指定为请求处理程序的模块 - 将不起作用。您可以从请求处理程序模块调用 deferred.defer,但您传递给它的函数必须在其他地方定义!
所以传递方法autofavoritetweettask
不起作用autofavoritetweet
?但是为什么它大部分时间都有效:
错误只是在加载模块时出现。我不明白为什么有时所有模块都加载到任务队列中,但有时却没有。
谢谢你。更新 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
解决方案
推荐阅读
- sql - 计算特定时间范围内的访问次数
- automation - Jira 生日 JQL 查询
- php - PHP Slim-3:如何在内部重定向到另一个路由
- android - Flutter Build APK:任务“:speech_recognition:verifyReleaseResources”执行失败
- ruby-on-rails - 符号声明中的presents是什么意思?
- react-native - 在 react native expo 中成功登录后如何重定向到仪表板屏幕?
- python-3.x - 如何以日历年的形式重新排列python中的月份列表
- java - 在java中,如何交换Vector中的两个值?
- python - python中的时间和空间分析
- html - 将一个标签居中并在同一 div 的底部放置一个