EncodeError:<flask_mail.message object =“”at =“”0x7f044bf07410 =“”>不是JSON可序列化的

时间:2017-11-22 13:09:19

标签: flask celery

我的最终代码如下所示:

@client_route.route('/client/cat-<dir_code>/subscribe/<string:user_id>', methods=['POST'])
@only_client
@is_active_client
# @cache.cached(timeout=60)
def subscribe_abonent(user_id):

    search_form = Search()
    client_id = Client.query.filter_by(tele=session.get('client_phone') ,name=session.get('client_logged_in'), family=session.get('client_family')).first_or_404()
    master = Abonent.query.filter_by(public_id=user_id, slug_direction=g.get('current_directory')).first_or_404()
    client = Client.query.filter_by(id=client_id.id).first_or_404()

    if session.get('client_is_not_subscriber'):
        session.pop('client_is_not_subscriber')
    session['client_is_subscriber'] = client.name + client.family + str(client.id)

        socketio.emit('show_calendar', namespace='/masterCalendar-{}'.format(master.slug, master.public_id.replace('-','')))

        if master.email is not None:
            if master.subscribers_notifications:
                date_now = datetime.now()
                send_email(master.email, 'You got a new subscriber','client/newsletter/new_subscriber',master=master.name + ' ' + master.family, client=client.name + " " + client.family, sent=date_now)

@celery.task
def send_email(to, subject, template, **kwargs):
    with current_app.app_context():
        msg = Message(current_app.config['UBOOK_MAIL_SUBJECT_PREFIX'] + ' ' + subject,
                sender=current_app.config['UBOOK_MAIL_SENDER'], recipients=[to])
        msg.body = render_template(template + '.txt', **kwargs)
        msg.html = render_template(template + '.html', **kwargs)
        mail.send(msg)

现在一切正常,但芹菜没有认识到任务,任务在终端内运行,就像你使用Thread发送电子邮件一样!!!

new_subscriber.txt

Dear Vladimir, Here was {{master}}

You got a new subscriber:

Клиент: Sasha , Here was {{client}}

Получено: 2017-11-23 12:47:23 , Here was {{sent}}

我忘了提到的另一件事,如果我删除了主,客户端和发送的参数并使用delay()代码被冻结!!

0 个答案:

没有答案