line / line-bot-sdk-python

LINE Messaging API SDK for Python
https://pypi.python.org/pypi/line-bot-sdk
Apache License 2.0
1.93k stars 1.02k forks source link

Webhook URL cannot be verified. #37

Closed Deen12520 closed 7 years ago

Deen12520 commented 7 years ago

I use the codes in my project directly and I deploy my project onHeroku successfully.

The codes what I use is:

from flask import Flask, request, abort

from linebot import (
    LineBotApi, WebhookHandler
)
from linebot.exceptions import (
    InvalidSignatureError
)
from linebot.models import (
    MessageEvent, TextMessage, TextSendMessage,
)

app = Flask(__name__)

line_bot_api = LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN')   #I put my 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()

But the error appeared like that:

https://intense-anchorage-90708.herokuapp.com/callback A http status of the response was '500 INTERNAL SERVER ERROR'.

I need your help. Thanks a lot.

be-hase commented 7 years ago

Do you press the verify-button in the Developer Center?

This "Verify" means verifying SSL certificate. When you click this verify-button, LINE server sends a dummy webhook. And reply token included webhook is also dummy. So, it is impossible to call reply API.

Deen12520 commented 7 years ago

Sorry, I can't get what you say. In fact, I have pressed the verity button. After I clicked the button,the "'500 INTERNAL SERVER ERROR'." occured.

There are something that I confused: 1. Can I use the code directly which I listed in my first problem?

  1. What's the dummy Webhook? dummy reply Token? I have put my Channel Access Token in my codes.

I'm looking forward for your answers. Thanks a lot.

Deen12520 commented 7 years ago

The errors like this:

2017-04-06T12:40:06.136826+00:00 heroku[router]: at=info method=POST path="/callback" host=line-bot-flaskr.herokuapp.com request_id=fdf96bda-17b9-4428-b60a-d353bee22a7a fwd="203.104.132.58" dyno=web.1 connect=1ms service=846ms status=500 bytes=456 protocol=https
2017-04-06T12:40:06.135006+00:00 app[web.1]: [2017-04-06 12:40:06,132] ERROR in app: Exception on /callback [POST]
2017-04-06T12:40:06.135017+00:00 app[web.1]: Traceback (most recent call last):
2017-04-06T12:40:06.135018+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
2017-04-06T12:40:06.135019+00:00 app[web.1]:     response = self.full_dispatch_request()
2017-04-06T12:40:06.135020+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
2017-04-06T12:40:06.135020+00:00 app[web.1]:     rv = self.handle_user_exception(e)
2017-04-06T12:40:06.135021+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
2017-04-06T12:40:06.135022+00:00 app[web.1]:     reraise(exc_type, exc_value, tb)
2017-04-06T12:40:06.135023+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2017-04-06T12:40:06.135023+00:00 app[web.1]:     raise value
2017-04-06T12:40:06.135024+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
2017-04-06T12:40:06.135025+00:00 app[web.1]:     rv = self.dispatch_request()
2017-04-06T12:40:06.135025+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2017-04-06T12:40:06.135027+00:00 app[web.1]:     return self.view_functions[rule.endpoint](**req.view_args)
2017-04-06T12:40:06.135028+00:00 app[web.1]:   File "/app/hello.py", line 32, in callback
2017-04-06T12:40:06.135028+00:00 app[web.1]:     handler.handle(body, signature)
2017-04-06T12:40:06.135029+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/linebot/webhook.py", line 227, in handle
2017-04-06T12:40:06.135030+00:00 app[web.1]:     func(event)
2017-04-06T12:40:06.135030+00:00 app[web.1]:   File "/app/hello.py", line 43, in handle_message
2017-04-06T12:40:06.135031+00:00 app[web.1]:     TextSendMessage(text=event.message.text))
2017-04-06T12:40:06.135032+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/linebot/api.py", line 94, in reply_message
2017-04-06T12:40:06.135032+00:00 app[web.1]:     '/v2/bot/message/reply', data=json.dumps(data), timeout=timeout
2017-04-06T12:40:06.135033+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/linebot/api.py", line 262, in _post
2017-04-06T12:40:06.135034+00:00 app[web.1]:     self.__check_error(response)
2017-04-06T12:40:06.135034+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/linebot/api.py", line 271, in __check_error
2017-04-06T12:40:06.135035+00:00 app[web.1]:     raise LineBotApiError(response.status_code, error)
2017-04-06T12:40:06.135040+00:00 app[web.1]: linebot.exceptions.LineBotApiError: <LineBotApiError [Invalid reply token]>
2017-04-06T12:42:11.392731+00:00 heroku[router]: at=info method=POST path="/callback" host=line-bot-flaskr.herokuapp.com request_id=2447eb31-02b1-4964-8ccd-9eafeb9508 fwd="203.114.135.61" dyno=web.1 connect=1ms service=490ms status=500 bytes=456 protocol=https
2017-04-06T12:42:11.369481+00:00 app[web.1]: [2017-04-06 12:42:11,368] ERROR in app: Exception on /callback [POST]
2017-04-06T12:42:11.369497+00:00 app[web.1]: Traceback (most recent call last):

how to solve the problem? ## ERROR in app: Exception on /callback [POST]

my callback function

@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'

I need your help. Thanks a lot.

be-hase commented 7 years ago

You don't need to press verity button. I said thad this "Verify" means verifying SSL certificate.

Let's send a some text message to your BOT in LINE app. Then BOT may reply echo-text.

Deen12520 commented 7 years ago

orz. I get it .

I try it. Thanks a lot.

be-hase commented 7 years ago

When you press the verify button, LINE Server send a webhook.
But it is dummy. Your server receive webhook and try to call Reply API. But reply token is also dummy, so it failed...

Error log which you paste said "Invalid reply token".

2017-04-06T12:40:06.135040+00:00 app[web.1]: linebot.exceptions.LineBotApiError: <LineBotApiError [Invalid reply token]>

Thanks. :D

Deen12520 commented 7 years ago

ok.
Thanks.

Deen12520 commented 7 years ago

It doesn't matter whether you verify webhook url or not. My error comes from that I didn't clike the "confirm" on my mobile phone.

My problem is gone. @be-hase Thanks a lot.

be-hase commented 7 years ago

Oh. It is good that the problem is gone. Thanks.

kumarmanish511 commented 6 years ago

The webhook returned an invalid HTTP status code. (The expected status code is 200.)

EriecTanijaya commented 6 years ago

same problem

BibekStha123 commented 5 years ago

Thank you be-hase.