gpt4 book ai didi

Python Flask 电子邮件 KeyError KeyError : 'mail'

转载 作者:行者123 更新时间:2023-11-28 20:43:41 27 4
gpt4 key购买 nike

我在使用 Python Flask 和 Flask-Mail 库时遇到问题。

我收到一个错误:

KeyError: 'mail'

谁能帮我解决这个问题?

我的代码是:

# -*- coding: utf-8 -*-
from flask import Flask
from flask.ext.mail import Message
from flask.ext.mail import Mail
from ws import app


class Email():

def __init__(self):
""
#
# Enviar el email
#
def enviar_mail(self,subject, sender, recipients, text_body="hola mundo txt", html_body="hola mundo html"):
app = Flask(__name__)

app.config.update(dict(
MAIL_SERVER = 'smtp.gmail.com',
MAIL_PORT = 465,
MAIL_USE_TLS = False,
MAIL_USE_SSL = True,
MAIL_USERNAME = 'miaccount@gmail.com',
MAIL_PASSWORD = 'mypasswd$%'
))

mail = Mail(app)
mail.init_app(app)
msg = Message("Hello", sender="miaccount@gmail.com",recipients=["myrecipient@hotmail.com"])
msg.body = "testing"
msg.html = "<b>testing</b>"
mail.send(msg)

错误是

KeyError
KeyError: 'mail'
Traceback (most recent call last)
File "/home/javier/python/wszbeltia/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__

mail.send(msg)
File "/home/javier/python/wszbeltia/lib/python2.7/site-packages/flask_mail.py", line 492, in send

message.send(connection)
File "/home/javier/python/wszbeltia/lib/python2.7/site-packages/flask_mail.py", line 427, in send

connection.send(self)
File "/home/javier/python/wszbeltia/lib/python2.7/site-packages/flask_mail.py", line 190, in send

message.as_bytes() if PY3 else message.as_string(),
File "/home/javier/python/wszbeltia/lib/python2.7/site-packages/flask_mail.py", line 381, in as_string

return self._message().as_string()
File "/home/javier/python/wszbeltia/lib/python2.7/site-packages/flask_mail.py", line 307, in _message

**ascii_attachments = current_app.extensions['mail'].ascii_attachments
KeyError: 'mail'**

最佳答案

降级到flask_mail==0.9.0

这似乎是版本 0.9.1 中的回归。

关于Python Flask 电子邮件 KeyError KeyError : 'mail' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28466384/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com