我创建了一个简单的烧瓶服务器,在React中提交表单后,它将电子邮件发送到我的收件箱中。本地一切正常,但是当我想将flask服务器部署到heroku flask应用程序崩溃时。我创建一个包含web: gunicorn app:app
的Procfile。然后,我用heroku create webapp
然后用git push heroku master
创建了一个heroku应用。
...
smtp = smtplib.SMTP(os.getenv('HOST'), os.getenv('PORT'))
smtp.connect(os.getenv('HOST'), os.getenv('PORT'))
smtp.starttls()
email = os.getenv('EMAIL')
sender = email
receivers = [email]
smtp.login(sender, os.getenv('EMAIL_PASSWORD'))
@app.route('/')
def index():
return 'Hello'
@app.route('/email', methods=['POST'])
def email():
if request.method == 'POST':
data = request.get_json()
subject = data['subject']
msg = 'Subject: {}\n\n{}'.format(subject, data['message'])
smtp.sendmail(sender, receivers, msg)
return jsonify({
'status': 200,
'message': msg
})
...
2019-07-28T18:12:33.937982+00:00 app[web.1]: [2019-07-28 18:12:33 +0000] [18] [INFO] Booting worker with pid: 18
2019-07-28T18:12:33.993226+00:00 app[web.1]: [2019-07-28 18:12:33 +0000] [19] [INFO] Booting worker with pid: 19
2019-07-28T18:12:39.410525+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=flask-email.herokuapp.com request_id=fd1af62f-83d0-4f9d-ba65-1db3ca7cece0 fwd="79.184.216.122" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
2019-07-28T18:13:04.073908+00:00 app[web.1]: [2019-07-28 18:13:04 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:18)
2019-07-28T18:13:04.074123+00:00 app[web.1]: [2019-07-28 18:13:04 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:19)
2019-07-28T18:13:04.075458+00:00 app[web.1]: [2019-07-28 18:13:04 +0000] [19] [INFO] Worker exiting (pid: 19)
2019-07-28T18:13:04.077513+00:00 app[web.1]: [2019-07-28 18:13:04 +0000] [18] [INFO] Worker exiting (pid: 18)
2019-07-28T18:13:04.242006+00:00 app[web.1]: [2019-07-28 18:13:04 +0000] [22] [INFO] Booting worker with pid: 22
2019-07-28T18:13:04.301452+00:00 app[web.1]: [2019-07-28 18:13:04 +0000] [23] [INFO] Booting worker with pid: 23
2019-07-28T18:13:11.878256+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/favicon.ico" host=flask-email.herokuapp.com request_id=59a38b71-3528-4fd0-b2d3-55ada94ae412 fwd="79.184.216.122" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
2019-07-28T18:13:34.417382+00:00 app[web.1]: [2019-07-28 18:13:34 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:22)
2019-07-28T18:13:34.418066+00:00 app[web.1]: [2019-07-28 18:13:34 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:23)
2019-07-28T18:13:34.420999+00:00 app[web.1]: [2019-07-28 18:13:34 +0000] [23] [INFO] Worker exiting (pid: 23)
2019-07-28T18:13:34.423371+00:00 app[web.1]: [2019-07-28 18:13:34 +0000] [22] [INFO] Worker exiting (pid: 22)
2019-07-28T18:13:34.681826+00:00 app[web.1]: [2019-07-28 18:13:34 +0000] [26] [INFO] Booting worker with pid: 26
2019-07-28T18:13:34.721334+00:00 app[web.1]: [2019-07-28 18:13:34 +0000] [27] [INFO] Booting worker with pid: 27
当我查看日志时,看到一个H10错误,这意味着App崩溃了。我的问题是为什么?