为了账号安全,请及时绑定邮箱和手机立即绑定

python flask mail api 报错

python flask mail api 报错

波斯汪 2019-05-21 17:30:53
#!/usr/bin/envpython#coding:utf-8fromflaskimportFlask,requestfromflask_mailimportMail,Messageapp=Flask(__name__)app.config['MAIL_SERVER']='smtp.139.com'app.config['MAIL_PORT']=465app.config['MAIL_USE_SSL']=Trueapp.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)returnstatusdefsend_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()returnthrif__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.comTraceback(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_appresponse=self.handle_exception(e)File"C:\Python27\lib\site-packages\flask\app.py",line1540,inhandle_exceptionreraise(exc_type,exc_value,tb)File"C:\Python27\lib\site-packages\flask\app.py",line1982,inwsgi_appresponse=self.full_dispatch_request()File"C:\Python27\lib\site-packages\flask\app.py",line1615,infull_dispatch_requestreturnself.finalize_request(rv)File"C:\Python27\lib\site-packages\flask\app.py",line1630,infinalize_requestresponse=self.make_response(rv)File"C:\Python27\lib\site-packages\flask\app.py",line1740,inmake_responserv=self.response_class.force_type(rv,request.environ)File"C:\Python27\lib\site-packages\werkzeug\wrappers.py",line921,inforce_typeresponse=BaseResponse(*_run_wsgi_app(response,environ))File"C:\Python27\lib\site-packages\werkzeug\wrappers.py",line59,in_run_wsgi_appreturn_run_wsgi_app(*args)File"C:\Python27\lib\site-packages\werkzeug\test.py",line923,inrun_wsgi_appapp_rv=app(environ,start_response)TypeError:'Thread'objectisnotcallable
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 529 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信