当我运行flask应用程序时,localhost没有运行,并且我收到OS:Error of 'No route to host‘错误。
我尝试添加了以下内容:
app.run(host='0.0.0.0')但它不work.Also我已经尝试更改端口从5000到4996和各种其他端口,但我仍然面临同样的问题。
下面是我的完整代码:
from flask import Flask
from flask_mail import Mail,Message
app = Flask(__name__)
app.config['DEBUG']=True
app.config['TESTING']=False
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT']=456
app.config['MAIL_USE_SSL']=True
#app.config['MAIL_DEBUG']=
app.config['MAIL_USERNAME']='trvt1234@gmail.com'
app.config['MAIL_PASSWORD']='#insert password here'
app.config['MAIL_DEFAULT_SENDER']='trvt1234@gmail.com'
app.config['MAIL_MAX_EMAILS']=None
#app.config['MAIL_SUPRESS_SEND']=
app.config['MAIL_ASCII_ATTACHMENTS']=False
email = Mail(app)
@app.route('/')
def mail():
message = Message('Hello',recipients=['trvt1234@gmail.com'])
email.send(message)
return('message sent successfully')
if __name__ == '__main__':
app.run(host='0.0.0.0')我是Flask的新手,正在考虑如何继续解决这个问题。
发布于 2019-05-06 08:07:49
我想你弄错了MAIL_PORT -它应该是465而不是456。
https://stackoverflow.com/questions/55983443
复制相似问题