Maitree Hirunteeyakun
Maitree Hirunteeyakun

Reputation: 191

'Blueprint' object has no attribute 'logger'

I following this tutorial https://medium.com/better-programming/line-bot-with-python-and-heroku-tutorial-e8c296f3816f . I want to create a webhook for LINE Messaging API using Flask app on Heroku.

I can't verify Webhook URL due to an Error "The webhook returned an HTTP status code other than 200"

So I check log in my Heroku app log console, it says

Traceback
File "/app/flask_myapp/routes/main.py", line 86, in linewebhook
main.logger.info("Request body: " + body)
AttributeError: 'Blueprint' object has no attribute 'logger'

Here is the source code from the tutorial that I add to my project

# /flask_myapp/routes/main.py

#Blueprint
main = Blueprint('main', __name__)

@main.route("/linewebhook", methods=['POST'])
def linewebhook():
# 監聽所有來自 /callback 的 Post Request
    # get X-Line-Signature header value
    signature = request.headers['X-Line-Signature']
    # get request body as text
    body = request.get_data(as_text=True)
    main.logger.info("Request body: " + body)                       #Traceback Here
    # handle webhook body
    try:
        handler.handle(body, signature)
    except InvalidSignatureError:
        abort(400)
    return 'OK'

# 處理訊息
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
    message = TextSendMessage(text=event.message.text)
    line_bot_api.reply_message(event.reply_token, message)

Here is my app code. https://github.com/H11Maitree/Face_Webapp

Upvotes: 1

Views: 2070

Answers (0)

Related Questions