나는이 매우 간단 플라스크/셀러리 응용 프로그램을 실행하려고 :flask_mail 메시지 인스턴스가 직렬화 JSON없는
@celery.task
def send_async_email(msg):
with app.app_context():
mail.send(msg)
@celery.task(bind=True)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'GET':
return render_template('index.html', email=session.get('email', ''))
email = request.form['email']
session['email'] = email
msg = Message('Hello from Flask',
recipients=[request.form['email']])
msg.body = 'This is a test email sent from a background Celery task.'
print type(msg)
print dir(msg)
print 'msg.send'
print msg.send
print 'msg'
print msg
if request.form['submit'] == 'Send':
send_async_email.delay(msg)
flash('Sending email to {0}'.format(email))
else:
return redirect(url_for('index'))
을하지만,이 메시지 클래스의 인스턴스가하지 않는, 직렬화 JSON되지 않기 때문에이 작동하지 않습니다
msg.send
<bound method Message.send of <flask_mail.Message object at 0x7ffa94cd0290>>
msg
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Hello from Flask
From: [email protected]
EncodeError: <flask_mail.Message object at 0x7ffa94cd0290> is not JSON serializable