我正在Heroku上创建一个Flask应用程序并且在使用Flask-Mail时遇到了问题。以下是相关的片段。我可以从命令行运行它们,它们正是我正在寻找的,但是当我将它们推送到Heroku时,我在页面上出现“内部服务错误”,并在日志中出现SMTP错误。
app.config.update(dict(
DEBUG = True,
MAIL_SERVER = 'smtp.gmail.com',
MAIL_PORT = 465,
MAIL_USE_TLS = False,
MAIL_USE_SSL = True,
MAIL_USERNAME = 'email@address.com'
MAIL_PASSWORD = 'password',
))
mail = Mail(app)
@app.route('/test1')
def test1():
msg = Message(
'Hello',
sender = 'email@address.com',
recipients = ['email@address.com'])
msg.body = "This is the email body"
msg.html = '<b>HTML</b> body'
with app.app_context():
mail.send(msg)
return "Sent"
错误日志:
2015-01-14T16:45:39.934703+00:00 heroku[api]: Deploy 4a36167 by xxxxx
2015-01-14T16:45:39.934735+00:00 heroku[api]: Release v47 created by xxxx
2015-01-14T16:45:40.155029+00:00 heroku[web.1]: State changed from up to startin
g
2015-01-14T16:45:44.644859+00:00 heroku[web.1]: Starting process with command `g
unicorn hello:app --log-file=-`
2015-01-14T16:45:45.635793+00:00 heroku[web.1]: Stopping all processes with SIGT
ERM
2015-01-14T16:45:46.391264+00:00 app[web.1]: [2015-01-14 16:45:46 +0000] [9] [IN
FO] Worker exiting (pid: 9)
2015-01-14T16:45:46.520663+00:00 app[web.1]: [2015-01-14 16:45:46 +0000] [3] [IN
FO] Handling signal: term
2015-01-14T16:45:46.391694+00:00 app[web.1]: [2015-01-14 16:45:46 +0000] [10] [I
NFO] Worker exiting (pid: 10)
2015-01-14T16:45:46.544635+00:00 app[web.1]: [2015-01-14 16:45:46 +0000] [3] [IN
FO] Shutting down: Master
2015-01-14T16:45:46.533446+00:00 app[web.1]: [2015-01-14 16:45:46 +0000] [2] [IN
FO] Starting gunicorn 19.1.1
2015-01-14T16:45:46.636720+00:00 app[web.1]: [2015-01-14 16:45:46 +0000] [9] [IN
FO] Booting worker with pid: 9
2015-01-14T16:45:46.534356+00:00 app[web.1]: [2015-01-14 16:45:46 +0000] [2] [IN
FO] Listening at: http://0.0.0.0:34086 (2)
2015-01-14T16:45:46.534457+00:00 app[web.1]: [2015-01-14 16:45:46 +0000] [2] [IN
FO] Using worker: sync
2015-01-14T16:45:46.552617+00:00 app[web.1]: [2015-01-14 16:45:46 +0000] [8] [IN
FO] Booting worker with pid: 8
2015-01-14T16:45:47.044825+00:00 heroku[web.1]: State changed from starting to u
p
2015-01-14T16:45:47.739308+00:00 heroku[web.1]: Process exited with status 0
2015-01-14T16:46:09.869192+00:00 app[web.1]: send: 'ehlo c71238d1-f910-49d1-bc16
-7459d247cc09.prvt.dyno.rt.heroku.com\r\n'
2015-01-14T16:46:10.115550+00:00 app[web.1]: reply: '534-5.7.14 <https://account
s.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbslc\r\n'
2015-01-14T16:46:09.898056+00:00 app[web.1]: reply: '250-mx.google.com at your s
ervice, [54.80.204.140]\r\n'
2015-01-14T16:46:09.898107+00:00 app[web.1]: reply: '250-SIZE 35882577\r\n'
2015-01-14T16:46:09.898150+00:00 app[web.1]: reply: '250-8BITMIME\r\n'
2015-01-14T16:46:09.900512+00:00 app[web.1]: reply: '250-AUTH LOGIN PLAIN XOAUTH
XOAUTH2 PLAIN-CLIENTTOKEN\r\n'
2015-01-14T16:46:09.900571+00:00 app[web.1]: reply: '250-ENHANCEDSTATUSCODES\r\n
'
2015-01-14T16:46:09.900664+00:00 app[web.1]: reply: '250-PIPELINING\r\n'
2015-01-14T16:46:09.900712+00:00 app[web.1]: reply: '250-CHUNKING\r\n'
2015-01-14T16:46:09.900754+00:00 app[web.1]: reply: '250 SMTPUTF8\r\n'
2015-01-14T16:46:09.900777+00:00 app[web.1]: SIZE 35882577
2015-01-14T16:46:09.900779+00:00 app[web.1]: 8BITMIME
2015-01-14T16:46:09.900780+00:00 app[web.1]: AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLA
IN-CLIENTTOKEN
2015-01-14T16:46:09.900782+00:00 app[web.1]: ENHANCEDSTATUSCODES
2015-01-14T16:46:09.900784+00:00 app[web.1]: CHUNKING
2015-01-14T16:46:10.115765+00:00 app[web.1]: reply: '534-5.7.14 4iAW28c8vufOttcf
GrvizdqdylcDOqzOHbYqsR5Go9d9aNQeUPHsSQWUAwSKAxcvbJL1sY\r\n'
2015-01-14T16:46:09.900786+00:00 app[web.1]: SMTPUTF8
2015-01-14T16:46:10.116531+00:00 app[web.1]: reply: retcode (534); Msg: 5.7.14 <
https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbslc
2015-01-14T16:46:10.116314+00:00 app[web.1]: reply: '534-5.7.14 Learn more at\r\
n'
2015-01-14T16:46:10.116094+00:00 app[web.1]: reply: '534-5.7.14 Bkxu93yI9jIqsf-d
t2670QFgD1TRoKjFxukJLEjYkLpmxV0hHbFiE7Zkq_rxKLCpl0apIT\r\n'
2015-01-14T16:46:10.116533+00:00 app[web.1]: 5.7.14 4iAW28c8vufOttcfGrvizdqdylcD
OqzOHbYqsR5Go9d9aNQeUPHsSQWUAwSKAxcvbJL1sY
2015-01-14T16:46:09.900783+00:00 app[web.1]: PIPELINING
2015-01-14T16:46:09.900775+00:00 app[web.1]: reply: retcode (250); Msg: mx.googl
e.com at your service, [54.80.204.140]
2015-01-14T16:46:09.901703+00:00 app[web.1]: send: 'AUTH PLAIN AHRsYW1hbm5hNDJAZ
21haWwuY29tAGFzc2hvbGUxIw==\r\n'
2015-01-14T16:46:10.116539+00:00 app[web.1]: 5.7.14 Learn more at
2015-01-14T16:46:10.121865+00:00 app[web.1]: [2015-01-14 16:46:10 +0000] [8] [ER
ROR] Error handling request
2015-01-14T16:46:10.121870+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/sync.py", line 93, in handle
2015-01-14T16:46:10.115933+00:00 app[web.1]: reply: '534-5.7.14 IC3NFfTdmSkdrCIc
w0WCp1T8U7P5PDGC_3guG0ACIxKNiwbls5Pq7oXeKVr5xJGuiXXe_E\r\n'
2015-01-14T16:46:10.116538+00:00 app[web.1]: 5.7.14 Nfze3jA> Please log in via y
our web browser and then try again.
2015-01-14T16:46:10.116509+00:00 app[web.1]: reply: '534 5.7.14 https://support.
google.com/mail/bin/answer.py?answer=78754 t9sm20975983qak.14 - gsmtp\r\n'
2015-01-14T16:46:10.121872+00:00 app[web.1]: self.handle_request(listener, r
eq, client, addr)
2015-01-14T16:46:10.121877+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask/app.py", line 1836, in __call__
2015-01-14T16:46:10.116536+00:00 app[web.1]: 5.7.14 Bkxu93yI9jIqsf-dt2670QFgD1TR
oKjFxukJLEjYkLpmxV0hHbFiE7Zkq_rxKLCpl0apIT
2015-01-14T16:46:10.116239+00:00 app[web.1]: reply: '534-5.7.14 Nfze3jA> Please
log in via your web browser and then try again.\r\n'
2015-01-14T16:46:10.121899+00:00 app[web.1]: response = self.full_dispatch_r
equest()
2015-01-14T16:46:10.116535+00:00 app[web.1]: 5.7.14 IC3NFfTdmSkdrCIcw0WCp1T8U7P5
PDGC_3guG0ACIxKNiwbls5Pq7oXeKVr5xJGuiXXe_E
2015-01-14T16:46:10.116541+00:00 app[web.1]: 5.7.14 https://support.google.com/m
ail/bin/answer.py?answer=78754 t9sm20975983qak.14 - gsmtp
2015-01-14T16:46:10.121869+00:00 app[web.1]: Traceback (most recent call last):
2015-01-14T16:46:10.121874+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/gunicorn/workers/sync.py", line 134, in handle_request
2015-01-14T16:46:10.121875+00:00 app[web.1]: respiter = self.wsgi(environ, r
esp.start_response)
2015-01-14T16:46:10.121878+00:00 app[web.1]: return self.wsgi_app(environ, s
tart_response)
2015-01-14T16:46:10.121900+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
2015-01-14T16:46:10.121902+00:00 app[web.1]: rv = self.handle_user_exception
(e)
2015-01-14T16:46:10.121891+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask/app.py", line 1820, in wsgi_app
2015-01-14T16:46:10.121896+00:00 app[web.1]: reraise(exc_type, exc_value, tb
)
2015-01-14T16:46:10.121912+00:00 app[web.1]: File "/app/hello.py", line 49, in
test1
2015-01-14T16:46:10.121893+00:00 app[web.1]: response = self.make_response(s
elf.handle_exception(e))
2015-01-14T16:46:10.121904+00:00 app[web.1]: reraise(exc_type, exc_value, tb
)
2015-01-14T16:46:10.121894+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask/app.py", line 1403, in handle_exception
2015-01-14T16:46:10.121897+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask/app.py", line 1817, in wsgi_app
2015-01-14T16:46:10.121906+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
2015-01-14T16:46:10.121910+00:00 app[web.1]: return self.view_functions[rule
.endpoint](**req.view_args)
2015-01-14T16:46:10.121903+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
2015-01-14T16:46:10.121909+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask/app.py", line 1461, in dispatch_request
2015-01-14T16:46:10.121914+00:00 app[web.1]: mail.send(msg)
2015-01-14T16:46:10.121916+00:00 app[web.1]: with self.connect() as connecti
on:
2015-01-14T16:46:10.121918+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask_mail.py", line 144, in __enter__
2015-01-14T16:46:10.121907+00:00 app[web.1]: rv = self.dispatch_request()
2015-01-14T16:46:10.121915+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask_mail.py", line 491, in send
2015-01-14T16:46:10.121923+00:00 app[web.1]: host.login(self.mail.username,
self.mail.password)
2015-01-14T16:46:10.121922+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/site-packages/flask_mail.py", line 165, in configure_host
2015-01-14T16:46:10.121925+00:00 app[web.1]: File "/app/.heroku/python/lib/pyt
hon2.7/smtplib.py", line 622, in login
2015-01-14T16:46:10.121926+00:00 app[web.1]: raise SMTPAuthenticationError(c
ode, resp)
2015-01-14T16:46:10.121920+00:00 app[web.1]: self.host = self.configure_host
()
2015-01-14T16:46:10.121928+00:00 app[web.1]: SMTPAuthenticationError: (534, '5.7
.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbslc\n5.7.
14 4iAW28c8vufOttcfGrvizdqdylcDOqzOHbYqsR5Go9d9aNQeUPHsSQWUAwSKAxcvbJL1sY\n5.7.1
4 IC3NFfTdmSkdrCIcw0WCp1T8U7P5PDGC_3guG0ACIxKNiwbls5Pq7oXeKVr5xJGuiXXe_E\n5.7.14
Bkxu93yI9jIqsf-dt2670QFgD1TRoKjFxukJLEjYkLpmxV0hHbFiE7Zkq_rxKLCpl0apIT\n5.7.14
Nfze3jA> Please log in via your web browser and then try again.\n5.7.14 Learn mo
re at\n5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 t9sm209
75983qak.14 - gsmtp')
2015-01-14T16:46:10.123418+00:00 heroku[router]: at=info method=GET path="/test1
" host=xxx request_id=e963e219-030f-4f94-bd7d-ba695f
d9db24 fwd="8.34.183.2" dyno=web.1 connect=6ms service=358ms status=500 bytes=24
4