前提・実現したいこと
下記urlを参考におうむ返しするlinebotの作成がしたい。
https://qiita.com/krocks96/items/67f7510b36945eb9689b
https://cppx.hatenablog.com/entry/2017/10/31/165128
発生している問題・エラーメッセージ
LINE developersでWebhockURLの接続確認をすると、以下のようなエラーがでます。
エラーメッセージ Webhookが無効なHTTPステータスコードを返しました(期待されるステータスコードは200です)
###使用コード
from flask import Flask, request, abort from linebot import ( LineBotApi, WebhookHandler ) from linebot.exceptions import ( InvalidSignatureError ) from linebot.models import ( MessageEvent, TextMessage, TextSendMessage, ) import os app = Flask(__name__) #環境変数取得 YOUR_CHANNEL_ACCESS_TOKEN = os.environ["YOUR_CHANNEL_ACCESS_TOKEN"] YOUR_CHANNEL_SECRET = os.environ["YOUR_CHANNEL_SECRET"] line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN) handler = WebhookHandler(YOUR_CHANNEL_SECRET) @app.route("/callback", methods=['POST']) def callback(): # get X-Line-Signature header value signature = request.headers['X-Line-Signature'] # get request body as text body = request.get_data(as_text=True) app.logger.info("Request body: " + body) # handle webhook body try: handler.handle(body, signature) except InvalidSignatureError: abort(400) return 'OK' @handler.add(MessageEvent, message=TextMessage) def handle_message(event): line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text)) if __name__ == "__main__": # app.run() port = int(os.getenv("PORT", 5000)) app.run(host="0.0.0.0", port=port)
最新のログ
2019-05-14T01:04:30.070058+00:00 heroku[web.1]: State changed from crashed to starting 2019-05-14T01:04:33.567318+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-05-14T01:04:35.732639+00:00 heroku[web.1]: State changed from starting to crashed 2019-05-14T01:04:35.717935+00:00 heroku[web.1]: Process exited with status 1 2019-05-14T01:04:35.634125+00:00 app[web.1]: File "main.py", line 1 2019-05-14T01:04:35.634167+00:00 app[web.1]: Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32 2019-05-14T01:04:35.634173+00:00 app[web.1]: ^ 2019-05-14T01:04:35.634226+00:00 app[web.1]: SyntaxError: invalid syntax 2019-05-14T06:45:54.457762+00:00 heroku[web.1]: State changed from crashed to starting 2019-05-14T06:45:58.905314+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-05-14T06:46:01.255307+00:00 heroku[web.1]: State changed from starting to crashed 2019-05-14T06:46:01.239201+00:00 heroku[web.1]: Process exited with status 1 2019-05-14T06:46:01.151287+00:00 app[web.1]: File "main.py", line 1 2019-05-14T06:46:01.151319+00:00 app[web.1]: Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32 2019-05-14T06:46:01.151321+00:00 app[web.1]: ^ 2019-05-14T06:46:01.151323+00:00 app[web.1]: SyntaxError: invalid syntax 2019-05-14T11:25:31.000000+00:00 app[api]: Build started by user アドレス 2019-05-14T11:25:53.952041+00:00 heroku[web.1]: State changed from crashed to starting 2019-05-14T11:25:53.739231+00:00 app[api]: Deploy cbdbee86 by user アドレス 2019-05-14T11:25:53.739231+00:00 app[api]: Release v15 created by user アドレス 2019-05-14T11:25:58.079912+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-05-14T11:26:00.176928+00:00 heroku[web.1]: State changed from starting to crashed 2019-05-14T11:26:00.203005+00:00 heroku[web.1]: State changed from crashed to starting 2019-05-14T11:26:00.077691+00:00 app[web.1]: File "main.py", line 1 2019-05-14T11:26:00.077716+00:00 app[web.1]: Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32 2019-05-14T11:26:00.077718+00:00 app[web.1]: ^ 2019-05-14T11:26:00.077744+00:00 app[web.1]: SyntaxError: invalid syntax 2019-05-14T11:26:00.129501+00:00 heroku[web.1]: Process exited with status 1 2019-05-14T11:26:02.000000+00:00 app[api]: Build succeeded 2019-05-14T11:26:03.449684+00:00 heroku[web.1]: Starting process with command `python main.py` 2019-05-14T11:26:05.367169+00:00 heroku[web.1]: State changed from starting to crashed 2019-05-14T11:26:05.350272+00:00 heroku[web.1]: Process exited with status 1 2019-05-14T11:26:05.295818+00:00 app[web.1]: File "main.py", line 1 2019-05-14T11:26:05.295864+00:00 app[web.1]: Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32 2019-05-14T11:26:05.295869+00:00 app[web.1]: ^ 2019-05-14T11:26:05.295873+00:00 app[web.1]: SyntaxError: invalid syntax 2019-05-14T11:27:03.227451+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/callback" host=アプリ名 request_id=a79d7fa3-4622-496a-9980-2ac9bb6ffab8 fwd="203.104.156.76" dyno= connect= service= status=503 bytes= protocol=https 2019-05-14T11:27:29.111776+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/callback" host=アプリ名 request_id=83591001-2da1-4c47-a7ce-a15ee6ec1a22 fwd="147.92.149.166" dyno= connect= service= status=503 bytes= protocol=https
補足情報(FW/ツールのバージョンなど)
・コードは下記サイトのmain.pyからコピペしています。
https://qiita.com/krocks96/items/67f7510b36945eb9689b
・作成したアプリケーションのURLをブラウザで検索するとApplication errorと表示されます。
解決しておうむ返しできるようにしたいです。よろしくお願いします。
追記
コマンドラインでmain.pyを実行すると以下のように構文エラーが出ました。
File "main.py", line 1 Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32 ^ SyntaxError: invalid syntax
回答1件
あなたの回答
tips
プレビュー