我正在尝试使用flask.ext.mail发送电子邮件,但是我收到以下错误.我遵循了一些教程,他们似乎都在做同样的事情,我一直在四处寻找是否有人收到此错误并且没有找到它:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site xpackages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/aaronwishnick/Documents/Work/NewPersonalSite/app/views.py", …Run Code Online (Sandbox Code Playgroud) 我应该解释为什么我的问题不是重复的:TypeError:只能连接列表(不是"str")到列表
...所以它不是重复的,因为该帖子处理串联运算符+,出现在代码中; 我的问题在错误消息中有该运算符但在代码中没有.
这是相关的Flask代码,我查看了追溯(如下所示)......它看起来像
mail.sent(msg)
Run Code Online (Sandbox Code Playgroud)
线是进攻发生的地方.我已经尝试过很难解决这个问题,显然msg的内容有问题......但我无法弄清楚是什么.任何帮助将非常感激!
token = s.dumps(form.email.data, salt='email-confirm')
subject = 'subject goes here'
msg = Message(subject=subject, sender='recipient@email.com',
recipients=form.email.data)
link = url_for('confirm_email', token=token, _external=True)
pull_row = User.query.filter_by(email=form.email.data).first()
firstname = pull_row.firstname
msg.html = render_template("email_confirmationemail.html", link=link, name=firstname)
mail.send(msg)
return redirect(url_for('checkyouremail'))
Run Code Online (Sandbox Code Playgroud)
这是追溯
2017-08-07T06:00:05.982678+00:00 app[web.1]: Traceback (most recent call last):
2017-08-07T06:00:05.982679+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 130, in handle
2017-08-07T06:00:05.982680+00:00 app[web.1]: self.handle_request(listener, req, client, addr)
2017-08-07T06:00:05.982681+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 171, in handle_request
2017-08-07T06:00:05.982681+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2017-08-07T06:00:05.982682+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line …Run Code Online (Sandbox Code Playgroud) import os
import secrets
from PIL import Image
from flask import url_for, current_app
from flask_mail import Message
from app import mail
def save_picture(form_picture):
random_hex = secrets.token_hex(8)
f_name, f_ext = os.path.splitext(form_picture.filename)
picture_fn = random_hex + f_ext
picture_path = os.path.join(current_app.root_path, 'static/profile_pics', picture_fn)
output_size = (125, 125)
i = Image.open(form_picture)
i.thumbnail(output_size)
i.save(picture_path)
return picture_fn
def send_reset_email(user):
token = user.get_reset_token()
msg = Message('Password Reset Request', sender='noreplies@diemo.hr', recipients=[user.email])
msg.body = f''' To reset your password, visit the following link:
{url_for('users.reset_token', token=token, **_external=True**)}
If you did …Run Code Online (Sandbox Code Playgroud) 我正在探索烧瓶并尝试设置一个安全注册并登录的简单Web应用程序.我正在使用flask-security来执行此操作.不幸的是,当我导航到发送确认页面时,我收到错误:"smtpserverdisconnected:请先运行connect()".
以下是我写的相关文件.run.py驱动整个应用程序.
run.py(这是app文件夹旁边)
#!venv/bin/python
from app import app
app.run(debug = True)
Run Code Online (Sandbox Code Playgroud)
这里的所有内容都在app文件夹中
__init__ .py
from flask import Flask
from flask.ext.mail import Mail
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
mail = Mail(app)
import models
import views
@app.before_first_request
def create_user():
db.create_all()
models.user_datastore.create_user(email = 'user@example.com',
password = 'password')
db.session.commit()
if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud)
models.py
from app import db, app
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.security import SQLAlchemyUserDatastore,\
UserMixin, RoleMixin, Security
roles_users …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Flask-Mail 发送电子邮件。我与收件人一起创建了消息,但是AssertionError: No recipients have been added当我尝试发送它时我收到了。在下面的代码中,我打印出消息收件人,它们是正确的。我该如何解决这个错误?
from flask import Flask
from flask_mail import Message, Mail
app = Flask(__name__)
app.config.update(
DEBUG=True,
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT=465,
MAIL_USE_SSL=True,
MAIL_USERNAME='socialcreditsystem@gmail.com',
MAIL_PASSWORD='mypassword'
)
mail = Mail(app)
@app.route('/')
def hello_world():
msg=Message('hey hey hey', sender='socialcreditsystem@gmail.com', recipients=['julian.fink1000@gmail.com'])
print(msg.sender, msg.recipients)
# ('socialcreditsystem@googlemail.com', ['julian.fink1000@googlemail.com'])
print(msg.send_to)
# set(['julian.fink1000@googlemail.com'])
mail.send_message(msg)
return 'Hello World!'
if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud)
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\flask\app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app
response = …Run Code Online (Sandbox Code Playgroud) 我正在为我的 Flask 应用程序构建一个群发电子邮件组件。
我使用过flask_mail,并且能够使用'smtp.google.com'作为服务器发送它:
app.config['MAIL_SERVER']='smtp.gmail.com'
Run Code Online (Sandbox Code Playgroud)
为了启用它,我必须在 Gmail 中禁用双向身份验证,并打开“不太安全的应用程序”的访问权限。
鉴于安全级别降低,此设置的安全性如何?
有更安全的替代方案吗?
我正在使用烧瓶邮件。但是当我在 Flask 邮件的前端(react.js)调用其余 api 时,我收到此错误
“蓝图”对象没有属性“配置”
这是我的烧瓶邮件代码
from flask import Flask,Blueprint
from flask_mail import Mail, Message
app = Blueprint('app', __name__)
app.register_blueprint(url_prefix='/api/v1/SalesLead')
mail=Mail(app)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'myvar30@gmail.com'
app.config['MAIL_PASSWORD'] = '*****'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(leadHistoryController)
@app.route("/")
def index():
msg = Message('Sheraspace', sender = 'myvar30@gmail.com', recipients = ['jobaer.jhs@gmail.com'])
msg.body = "Hello jh"
mail.send(msg)
return "Sent again"
if __name__ == '__main__':
app.run(debug = True)
Run Code Online (Sandbox Code Playgroud)
蓝图配置有什么解决办法吗?或者我可以在前端使用其余的 api 而不使用蓝图吗?
from flask_mail import Mail,Message
from flask import Flask
Run Code Online (Sandbox Code Playgroud)
我正在尝试邮件但导致导入错误
我想在我的webapp中使用烧瓶邮件,我得知错误,我真的不明白.遵循指南,无法使其发挥作用.在以下过程中,我希望应用程序向新注册用户发送电子邮件.
配置:
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT=465,
MAIL_USE_SSL=True,
MAIL_USE_TLS=False,
MAIL_USERNAME = 'myMail@gmail.com',
MAIL_PASSWORD = '******'
Run Code Online (Sandbox Code Playgroud)
视图:
from flask_mail import Mail, Message
mail = Mail(app)
@app.route("/send_mail/")
def send_mail():
msg = Message('Hello', sender = 'myMail@gmail.com', recipients = ['somebody@gmail.com'])
msg.body = "This is the email body"
mail.send(msg)
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1994, in __call__
return self.wsgi_app(environ, start_response)
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "C:\venvs\test\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\venvs\test\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\venvs\test\lib\site-packages\flask\app.py", line …Run Code Online (Sandbox Code Playgroud) flask ×9
flask-mail ×9
python ×6
gmail ×1
importerror ×1
project ×1
reactjs ×1
security ×1
web ×1