猿问

python flask mail api 报错

#!/usr/bin/envpython
#coding:utf-8
fromflaskimportFlask,request
fromflask_mailimportMail,Message
app=Flask(__name__)
app.config['MAIL_SERVER']='smtp.139.com'
app.config['MAIL_PORT']=465
app.config['MAIL_USE_SSL']=True
app.config['MAIL_USERNAME']='1119527@139.com'
app.config['MAIL_PASSWORD']='11111'
app.config['MAIL_DEFAULT_SENDER']='119527@139.com'
mail=Mail(app)
importthreading
@app.route('/sendMail',methods=['POST','GET'])
defindex():
title=request.args.get('title')
content=request.args.get('content')
tolist=request.args.get('tolist')
tolist=str(tolist).split(',')
status=sendmail(title,content,tolist)
returnstatus
defsend_async_email(app,msg):
withapp.app_context():
mail.send(msg)
defsendmail(title,html,tolist):
msg=Message(title,recipients=tolist)
msg.html=html
#msg.body="Thisisafirstemail"
thr=threading.Thread(target=send_async_email,args=[app,msg])#创建线程
thr.start()
returnthr
if__name__=='__main__':
app.run(host='0.0.0.0',debug=True)
代码如上,功能是使用flaskmailapi异步发送邮件,使用curl调用的时候,报错不知道为什么Thread报错?模块验证过没问题。望指教
curlhttp://127.0.0.1:5000/sendMail?title=11\&content="222"\&tolist=33@qq.com
Traceback(mostrecentcalllast):
File"C:\Python27\lib\site-packages\flask\app.py",line1997,in__call__
returnself.wsgi_app(environ,start_response)
File"C:\Python27\lib\site-packages\flask\app.py",line1985,inwsgi_app
response=self.handle_exception(e)
File"C:\Python27\lib\site-packages\flask\app.py",line1540,inhandle_exception
reraise(exc_type,exc_value,tb)
File"C:\Python27\lib\site-packages\flask\app.py",line1982,inwsgi_app
response=self.full_dispatch_request()
File"C:\Python27\lib\site-packages\flask\app.py",line1615,infull_dispatch_request
returnself.finalize_request(rv)
File"C:\Python27\lib\site-packages\flask\app.py",line1630,infinalize_request
response=self.make_response(rv)
File"C:\Python27\lib\site-packages\flask\app.py",line1740,inmake_response
rv=self.response_class.force_type(rv,request.environ)
File"C:\Python27\lib\site-packages\werkzeug\wrappers.py",line921,inforce_type
response=BaseResponse(*_run_wsgi_app(response,environ))
File"C:\Python27\lib\site-packages\werkzeug\wrappers.py",line59,in_run_wsgi_app
return_run_wsgi_app(*args)
File"C:\Python27\lib\site-packages\werkzeug\test.py",line923,inrun_wsgi_app
app_rv=app(environ,start_response)
TypeError:'Thread'objectisnotcallable
波斯汪
浏览 530回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答