前提・実現したいこと
pythonを使ってそれをherokuにデプロイしてlineのおうむ返しのプログラムを作ろうとしています。
以下のサイトを参考にしました。
https://qiita.com/krocks96/items/67f7510b36945eb9689b
発生している問題・エラーメッセージ
そのサイトのうURLを開くと、 Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. と出て来ます。 また、linedeveloperのwebhookの設定のところでは「Webhookが無効なHTTPステータスコードを返しました(期待されるステータスコードは200です)」 そこでherokuのlogを確認したところ、以下のようなlogがでました。(一部省略) ユーザ名395+00:00 app[web.1]: reraise(exc_type, exc_value, tb) 2018-10-30T08:47:34.703396+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in rer aise 2018-10-30T08:47:34.703399+00:00 app[web.1]: raise value 2018-10-30T08:47:34.703400+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_ dispatch_request 2018-10-30T08:47:34.703402+00:00 app[web.1]: rv = self.dispatch_request() 2018-10-30T08:47:34.703403+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1598, in dispa tch_request 2018-10-30T08:47:34.703406+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args) 2018-10-30T08:47:34.703407+00:00 app[web.1]: File "line_bot.py", line 37, in callback 2018-10-30T08:47:34.703409+00:00 app[web.1]: handler.handle(body, signature) 2018-10-30T08:47:34.703411+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/linebot/webhook.py", line 227, in handle 2018-10-30T08:47:34.703412+00:00 app[web.1]: func(event) 2018-10-30T08:47:34.703414+00:00 app[web.1]: File "line_bot.py", line 48, in handle_message 2018-10-30T08:47:34.703415+00:00 app[web.1]: TextSendMessage(text=event.message.text)) 2018-10-30T08:47:34.703417+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/linebot/api.py", line 94, in reply _message 2018-10-30T08:47:34.703418+00:00 app[web.1]: '/v2/bot/message/reply', data=json.dumps(data), timeout=timeout 2018-10-30T08:47:34.703420+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/linebot/api.py", line 372, in _pos t 2018-10-30T08:47:34.703422+00:00 app[web.1]: self.__check_error(response) 2018-10-30T08:47:34.703423+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/linebot/api.py", line 381, in __ch eck_error 2018-10-30T08:47:34.703425+00:00 app[web.1]: raise LineBotApiError(response.status_code, error) 2018-10-30T08:47:34.706887+00:00 app[web.1]: linebot.exceptions.LineBotApiError: <LineBotApiError [Invalid reply token]> 2018-10-30T08:47:34.710948+00:00 app[web.1]: 10.111.224.2 - - [30/Oct/2018 08:47:34] "POST /callback HTTP/1.1" 500 - 2018-10-30T08:49:24.578305+00:00 heroku[router]: at=info method=GET path="/" host=linebot-0328.herokuapp.com request_id=beda40f7-1ba4 -4ada-a8ef-dbb9c0307d6b fwd="103.5.140.176" dyno=web.1 connect=1ms service=4ms status=404 bytes=380 protocol=https 2018-10-30T08:49:24.578038+00:00 app[web.1]: 10.31.74.203 - - [30/Oct/2018 08:49:24] "GET / HTTP/1.1" 404 - 2018-10-30T08:49:25.650288+00:00 heroku[router]: at=info method=GET path="/" host=linebot-0328.herokuapp.com request_id=3dbf0cf7-f72c -4018-87f6-81466771dd7b fwd="103.5.140.176" dyno=web.1 connect=2ms service=7ms status=404 bytes=380 protocol=https 2018-10-30T08:49:25.649929+00:00 app[web.1]: 10.31.74.203 - - [30/Oct/2018 08:49:25] "GET / HTTP/1.1" 404 - 2018-10-30T08:49:26.546435+00:00 heroku[router]: at=info method=GET path="/" host=linebot-0328.herokuapp.com request_id=dc91cbb5-891d -4c3d-b243-53232b0b5ba2 fwd="103.5.140.176" dyno=web.1 connect=1ms service=5ms status=404 bytes=380 protocol=https 2018-10-30T08:49:26.546093+00:00 app[web.1]: 10.31.74.203 - - [30/Oct/2018 08:49:26] "GET / HTTP/1.1" 404 - 2018-10-30T08:49:26.885646+00:00 heroku[router]: at=info method=GET path="/" host=linebot-0328.herokuapp.com request_id=b7ba7d39-16c9 -4dc3-939d-4051bf221e07 fwd="103.5.140.176" dyno=web.1 connect=1ms service=3ms status=404 bytes=380 protocol=https 2018-10-30T08:49:26.885377+00:00 app[web.1]: 10.31.74.203 - - [30/Oct/2018 08:49:26] "GET / HTTP/1.1" 404 - 2018-10-30T08:51:57.508440+00:00 heroku[router]: at=info method=GET path="/" host=linebot-0328.herokuapp.com request_id=5bd7f782-d6b7 -4322-8454-ffd03fc13e5b fwd="103.5.140.176" dyno=web.1 connect=0ms service=10ms status=404 bytes=380 protocol=https 2018-10-30T08:51:57.503725+00:00 app[web.1]: 10.45.249.93 - - [30/Oct/2018 08:51:57] "GET / HTTP/1.1" 404 - 2018-10-30T09:20:35.000000+00:00 app[api]: Build started by user ユーザ名 2018-10-30T09:20:51.139009+00:00 heroku[web.1]: Restarting 2018-10-30T09:20:51.139788+00:00 heroku[web.1]: State changed from up to starting 2018-10-30T09:20:52.184553+00:00 heroku[web.1]: Stopping all processes with SIGTERM 2018-10-30T09:20:52.340375+00:00 heroku[web.1]: Process exited with status 143 2018-10-30T09:20:50.835138+00:00 app[api]: Release v7 created by user ユーザ名 2018-10-30T09:20:50.835138+00:00 app[api]: Deploy 04973591 by user ユーザ名 2018-10-30T09:20:55.703663+00:00 heroku[web.1]: Starting process with command `python line_bot.py` 2018-10-30T09:21:01.131131+00:00 heroku[web.1]: State changed from starting to up 2018-10-30T09:21:00.954198+00:00 app[web.1]: * Running on http://0.0.0.0:41461/ (Press CTRL+C to quit) 2018-10-30T09:20:59.000000+00:00 app[api]: Build succeeded 2018-10-30T09:21:35.673786+00:00 heroku[router]: at=info method=GET path="/" host=linebot-0328.herokuapp.com request_id=bec43206-658d -4b02-a79b-e51e11cd2571 fwd="103.5.140.176" dyno=web.1 connect=1ms service=55ms status=404 bytes=380 protocol=https 2018-10-30T09:21:35.669787+00:00 app[web.1]: 10.11.176.130 - - [30/Oct/2018 09:21:35] "GET / HTTP/1.1" 404 - 2018-10-30T09:22:36.274038+00:00 heroku[router]: at=info method=GET path="/" host=linebot-0328.herokuapp.com request_id=c83500d9-3062 -4576-a3f8-a6a47107172b fwd="103.5.140.176" dyno=web.1 connect=2ms service=8ms status=404 bytes=380 protocol=https 2018-10-30T09:22:36.273479+00:00 app[web.1]: 10.45.123.32 - - [30/Oct/2018 09:22:36] "GET / HTTP/1.1" 404 - 2018-10-30T09:30:59.892002+00:00 heroku[web.1]: State changed from up to down 2018-10-30T09:31:01.092596+00:00 heroku[web.1]: Stopping all processes with SIGTERM 2018-10-30T09:31:01.196555+00:00 heroku[web.1]: Process exited with status 143 2018-10-30T09:30:59.810741+00:00 app[api]: Scaled to web@0:Free by user ユーザ名 2018-10-30T09:31:41.090859+00:00 heroku[web.1]: Starting process with command `python line_bot.py` line_bot.py44:48 LFUTF-8Python0 files 2018-10-30T09:31:36.374119+00:00 app[api]: Scaled to web@1:Free by user ユーザ名 2018-10-30T09:31:47.103644+00:00 heroku[web.1]: State changed from starting to up 2018-10-30T09:31:46.949519+00:00 app[web.1]: * Running on http://0.0.0.0:50128/ (Press CTRL+C to quit) 2018-10-30T09:34:50.717421+00:00 app[web.1]: 10.31.74.203 - - [30/Oct/2018 09:34:50] "GET / HTTP/1.1" 404 - 2018-10-30T09:34:50.718898+00:00 heroku[router]: at=info method=GET path="/" host=linebot-0328.herokuapp.com request_id=8510f199-f5a8 -4079-be1b-0f443d5aa2a9 fwd="103.5.140.176" dyno=web.1 connect=0ms service=40ms status=404 bytes=380 protocol=https 2018-10-30T10:09:44.999647+00:00 heroku[web.1]: Idling 2018-10-30T10:09:45.000127+00:00 heroku[web.1]: State changed from up to down 2018-10-30T10:09:46.063904+00:00 heroku[web.1]: Stopping all processes with SIGTERM 2018-10-30T10:09:46.155047+00:00 heroku[web.1]: Process exited with status 143 2018-10-30T11:52:23.975527+00:00 heroku[web.1]: Unidling 2018-10-30T11:52:23.976430+00:00 heroku[web.1]: State changed from down to starting
該当のソースコード
pythonのソースコードです
from linebot import ( LineBotApi, WebhookHandler ) from flask import Flask, request, abort 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"] YOUR_CHANNEL_ACCESS_TOKEN = "アクセストークン" 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)
試したこと
以前、herokuにデプロイした時、フレームワークがphpになっていたので修正しました。
しかし、結局同じエラーが出ました。
同じディレクトリの中には、requirements.txt、Procfile、runtime.pyがあります。
それぞれの中身は、
Flask==0.12.2
line-bot-sdk==1.5.0
web: python line_bot.py
python-3.6.5
となっています。
またlinedevelperのwebhookの画面で「Webhookが無効なHTTPステータスコードを返しました(期待されるステータスコードは200です)」というエラーが出ています。
補足情報(FW/ツールのバージョンなど)
python-3.6.5
Flask==0.12.2
line-bot-sdk==1.5.0
あなたの回答
tips
プレビュー