我正在尝试使用Celery将我的Flask应用程序转换为异步应用程序。该应用程序旨在接受请求,确定将请求路由到哪个函数,然后将请求和一些额外参数传递给相应的函数。当Celery被删除时,该应用程序正常工作,但在尝试使用该库时,我一直收到以下错误:
[2017-04-27 00:26:40,218: WARNING/MainProcess] celery@Johns-MacBook-Pro.local ready.
[2017-04-27 00:26:40,469: CRITICAL/MainProcess] Can't decode message body: DecodeError(RecursionError('maximum recursion depth exceeded while calling a Python object',),) [type:'application/x-python-serialize' encoding:'binary' headers:{}]
有谁可以指出我做错了什么?以下是我的代码摘录:
import json
from flask import Flask, request, g
from flask_restful import Resource, Api
from celery import Celery
app = Flask(__name__, instance_relative_config=True)
app.config.from_object('config.default')
api = Api(app)
import app_program
import util
# Celery settings
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
# The class for executing adjust
class Events(Resource):
n = app_program.AppProgram()
def get(self):
# Retrieve the specified parameters
params = request.args.to_dict()
params['request'] = request
if 'd' in params.keys(): # Handles
params.update(json.loads(params['d']))
del params['d']
# Determine if the visitor id exists
visitor_id, visitor_id_exists = self.n.visitor_id(**params)
params['visitor_id'] = visitor_id
# Save the pageview
if util.base_text(params['type'].lower()) == 'pageview':
self.save_pview.delay(**params)
else:
self.save_event.delay(**params)
return {"result": "success"}
@celery.task
def save_pview(self, params):
"""
Saves the pageview
:param params: the input parameters
:return:
"""
self.n.save_pview(**params)
@celery.task
def save_event(self, params):
"""
Saves the visitor event
:param params: the input parameters
:return:
"""
self.n.save_event(**params)
api.add_resource(Events, '/event')
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=8000)
错误消息似乎无法提供任何有用的信息:
[2017-04-27 00:39:31,584: CRITICAL/MainProcess] Can't decode message body: DecodeError(RecursionError('maximum recursion depth exceeded while calling a Python object',),) [type:'application/x-python-serialize' encoding:'binary' headers:{}]
body: b'\x80\x02}q\x00(X\x07\x00\x00\x00tasksetq\x01NX\t\x00\x00\x00timelimitq\x02NN\x86q\x03X\t\x00\x00\x00callbacksq\x04NX\x05\x00\x00\x00chordq\x05NX\x03\x00\x00\x00etaq\x06NX\x03\x00\x00\x00utcq\x07\x88X\x07\x00\x00\x00expiresq\x08NX\x04\x00\x00\x00taskq\tX\x0e\x00\x00\x00app.save_pviewq\nX\x08\x00\x00\x00errbacksq\x0bNX\x07\x00\x00\x00retriesq\x0cK\x00X\x04\x00\x00\x00argsq\r]q\x0eX\x02\x00\x00\x00idq\x0fX$\x00\x00\x0019430fd1-fc1d-41b5-9380-9bd4f5b9cc07q\x10X\x06\x00\x00\x00kwargsq\x11}q\x12(X\x07\x00\x00\x00fullurlq\x13X:\x00\x00\x00https://www.example.com#.q\x14X\n\x00\x00\x00visitor_idq\x15X$\x00\x00\x0021cb1d079cfffsdf8507ce18582cq\x16X\x0b\x00\x00\x00fingerprintq\x17X\x08\x00\x00\x0075201686q\x18X\x04\x00\x00\x00typeq\x19X\x08\x00\x00\x00pageviewq\x1aX\x08\x00\x00\x00timezoneq\x1bX\x03\x00\x00\x00ESTq\x1cX\t\x00\x00\x00visitoridq\x1dh\x16X\x07\x00\x00\x00requestq\x1ecwerkzeug.local\nLocalProxy\nq\x1f)\x81q... (677b)
另外,无论如何我可以让它打印出整个身体吗?