前提・実現したいこと
LINE BOTをherokuを使い開発しようとしています。
言語はPythonを使用しています。
今の状況として、Herokuにデプロイした際エラーが発生し、LINE BOTが上手く動いてくれません。
具体的には後述しますが、どうやらログを確認すると、at=error code=H10 desc="App crashed"と書かれているのでアプリがクラッシュしている(?)らしいのです。
他にも同様の質問はいくつか発見したのですが、そこに書かれている解決方法を試してみても改善できなかったので質問させてもらいました。
発生している問題・エラーメッセージ
2019-08-28T01:55:04.888229+00:00 app[web.1]: Traceback (most recent call last): 2019-08-28T01:55:04.888257+00:00 app[web.1]: File "main.py", line 1, in <module> 2019-08-28T01:55:04.888384+00:00 app[web.1]: main.py 2019-08-28T01:55:04.888388+00:00 app[web.1]: NameError: name 'main' is not defined 2019-08-28T01:57:58.393968+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/callback" host=casie-kitchensink.herokuapp.com request_id=75c19376-1aba-4347-9db4-1105f66a400c fwd="147.92.149.169" dyno= connect= service= status=503 bytes= protocol=https 2019-08-28T01:58:14.790216+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/callback" host=casie-kitchensink.herokuapp.com request_id=01e95ea4-2e7b-4492-b7ea-5cf642d40128 fwd="147.92.149.169" dyno= connect= service= status=503 bytes= protocol=https 2019-08-28T01:59:06.216447+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/callback" host=casie-kitchensink.herokuapp.com request_id=9e2d500a-1956-4017-b8c2-974027dbc661 fwd="147.92.149.169" dyno= connect= service= status=503 bytes= protocol=https 2019-08-28T02:02:31.784631+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/callback" host=casie-kitchensink.herokuapp.com request_id=9eefe2d5-9786-449f-8ef9-3a5261778d65 fwd="147.92.149.169" dyno= connect= service= status=503 bytes= protocol=https 2019-08-28T02:19:26.139324+00:00 heroku[web.1]: State changed from crashed to starting 2019-08-28T02:19:30.549895+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-08-28T02:19:32.455209+00:00 heroku[web.1]: Process exited with status 1 2019-08-28T02:19:32.474443+00:00 heroku[web.1]: State changed from starting to crashed 2019-08-28T02:19:32.406250+00:00 app[web.1]: Traceback (most recent call last): 2019-08-28T02:19:32.406276+00:00 app[web.1]: File "main.py", line 1, in <module> 2019-08-28T02:19:32.406452+00:00 app[web.1]: main.py 2019-08-28T02:19:32.406474+00:00 app[web.1]: NameError: name 'main' is not defined 2019-08-28T03:01:38.863459+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/callback" host=casie-kitchensink.herokuapp.com request_id=be5b6094-3414-47d0-82bf-ec4ed1faeff5 fwd="147.92.149.169" dyno= connect= service= status=503 bytes= protocol=https 2019-08-28T03:02:40.848748+00:00 heroku[web.1]: State changed from crashed to starting 2019-08-28T03:02:43.790927+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-08-28T03:02:45.620777+00:00 heroku[web.1]: State changed from starting to crashed 2019-08-28T03:02:45.594840+00:00 heroku[web.1]: Process exited with status 1 2019-08-28T03:02:45.551418+00:00 app[web.1]: Traceback (most recent call last): 2019-08-28T03:02:45.551451+00:00 app[web.1]: File "main.py", line 1, in <module> 2019-08-28T03:02:45.551570+00:00 app[web.1]: main.py 2019-08-28T03:02:45.551577+00:00 app[web.1]: NameError: name 'main' is not defined 2019-08-28T04:28:50.321540+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/callback" host=casie-kitchensink.herokuapp.com request_id=0d3fe463-6fb7-4332-874a-3d58be29469d fwd="147.92.149.169" dyno= connect= service= status=503 bytes= protocol=https 2019-08-28T04:32:54.716293+00:00 heroku[web.1]: State changed from crashed to starting 2019-08-28T04:32:58.897136+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-08-28T04:33:01.469942+00:00 heroku[web.1]: State changed from starting to crashed 2019-08-28T04:33:01.460080+00:00 heroku[web.1]: Process exited with status 1 2019-08-28T04:33:01.398906+00:00 app[web.1]: Traceback (most recent call last): 2019-08-28T04:33:01.398943+00:00 app[web.1]: File "main.py", line 1, in <module> 2019-08-28T04:33:01.399147+00:00 app[web.1]: main.py 2019-08-28T04:33:01.399181+00:00 app[web.1]: NameError: name 'main' is not defined 2019-08-28T04:57:02.850882+00:00 heroku[web.1]: State changed from crashed to starting 2019-08-28T04:57:02.630016+00:00 app[api]: @ref:fixie-silhouetted-42450 completed provisioning, setting FIXIE_URL. by user 'メールアドレス' 2019-08-28T04:57:02.630016+00:00 app[api]: Release v5 created by user 'メールアドレス' 2019-08-28T04:57:02.612791+00:00 app[api]: Attach FIXIE (@ref:fixie-silhouetted-42450) by user 'メールアドレス' 2019-08-28T04:57:02.612791+00:00 app[api]: Running release v4 commands by user 'メールアドレス' 2019-08-28T04:57:06.579572+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-08-28T04:57:08.446229+00:00 heroku[web.1]: State changed from starting to crashed 2019-08-28T04:57:08.461820+00:00 heroku[web.1]: State changed from crashed to starting 2019-08-28T04:57:08.372607+00:00 app[web.1]: Traceback (most recent call last): 2019-08-28T04:57:08.372650+00:00 app[web.1]: File "main.py", line 1, in <module> 2019-08-28T04:57:08.372805+00:00 app[web.1]: main.py 2019-08-28T04:57:08.372849+00:00 app[web.1]: NameError: name 'main' is not defined 2019-08-28T04:57:08.441990+00:00 heroku[web.1]: Process exited with status 1 2019-08-28T04:57:14.300638+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-08-28T04:57:16.422542+00:00 heroku[web.1]: State changed from starting to crashed 2019-08-28T04:57:16.420015+00:00 heroku[web.1]: Process exited with status 1 2019-08-28T04:57:16.347966+00:00 app[web.1]: Traceback (most recent call last): 2019-08-28T04:57:16.347998+00:00 app[web.1]: File "main.py", line 1, in <module> 2019-08-28T04:57:16.348093+00:00 app[web.1]: main.py 2019-08-28T04:57:16.348097+00:00 app[web.1]: NameError: name 'main' is not defined 2019-08-28T04:59:28.787802+00:00 app[api]: Set YOUR_CHANNEL_SECRET config vars by user 'メールアドレス' 2019-08-28T04:59:28.787802+00:00 app[api]: Release v6 created by user 'メールアドレス' 2019-08-28T04:59:30.035417+00:00 heroku[web.1]: State changed from crashed to starting 2019-08-28T04:59:33.166911+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-08-28T04:59:34.892095+00:00 heroku[web.1]: State changed from starting to crashed 2019-08-28T04:59:34.833798+00:00 app[web.1]: Traceback (most recent call last): 2019-08-28T04:59:34.833836+00:00 app[web.1]: File "main.py", line 1, in <module> 2019-08-28T04:59:34.833968+00:00 app[web.1]: main.py 2019-08-28T04:59:34.833974+00:00 app[web.1]: NameError: name 'main' is not defined 2019-08-28T04:59:34.878996+00:00 heroku[web.1]: Process exited with status 1 2019-08-28T05:00:03.955437+00:00 heroku[web.1]: State changed from crashed to starting 2019-08-28T05:00:03.664370+00:00 app[api]: Set YOUR_CHANNEL_ACCESS_TOKEN config vars by user 'メールアドレス'
該当のソースコード
python
1from flask import Flask, request, abort 2 3from linebot import ( 4 LineBotApi, WebhookHandler 5) 6from linebot.exceptions import ( 7 InvalidSignatureError 8) 9from linebot.models import ( 10 MessageEvent, TextMessage, TextSendMessage, 11) 12 13app = Flask(__name__) 14 15line_bot_api = LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN') 16handler = WebhookHandler('YOUR_CHANNEL_SECRET') 17 18 19@app.route("/callback", methods=['POST']) 20def callback(): 21 # get X-Line-Signature header value 22 signature = request.headers['X-Line-Signature'] 23 24 # get request body as text 25 body = request.get_data(as_text=True) 26 app.logger.info("Request body: " + body) 27 28 # handle webhook body 29 try: 30 handler.handle(body, signature) 31 except InvalidSignatureError: 32 abort(400) 33 34 return 'OK' 35 36 37@handler.add(MessageEvent, message=TextMessage) 38def handle_message(event): 39 line_bot_api.reply_message( 40 event.reply_token, 41 TextSendMessage(text=event.message.text)) 42 43 44if __name__ == "__main__": 45 app.run()
試したこと
herokuの再起動
$ heroku restart --app application_name
補足情報(FW/ツールのバージョンなど)
python 3.7.4
line-bot-sdkやFlaskはインストールをしましたが、よくわかりません。
情報不足であれば補足致しますが、どんな情報を補足すれば答えやすいかもわかっておりません。
あなたの回答
tips
プレビュー