LINE Messaging APIを用いてBOTを作成しています。
ロリポップの共有SSLを用いて実装したいのですが、うまくいきません。
Webhook URL ※SSLのみ対応 https://ドメイン名.ssl-lolipop.jp:443/省略/sources/main.cgi/callback Webhookが無効なHTTPステータスコードを返しました(期待されるステータスコードは200です)
色々とWebhook URLに入れてみても、上記のようなエラーメッセージが出てしまいます。
試したことは
①ローカルで作ったものをそのままで。
https://ドメイン名.ssl-lolipop.jp/省略/sources/main.py
https://ドメイン名.ssl-lolipop.jp/省略/sources/main.py/callback
https://ドメイン名.ssl-lolipop.jp:443/省略/sources/main.py
https://ドメイン名.ssl-lolipop.jp:443/省略/sources/main.py/callback
②main.pyと同じ階層に.htaccess(以下)を追加し、main.pyをmain.cgiに変え、ロリポップ!FTPにてmain.cgiの設定を700にして。
AddHandler cgi-script .py
https://ドメイン名.ssl-lolipop.jp/省略/sources/main.cgi
https://ドメイン名.ssl-lolipop.jp/省略/sources/main.cgi/callback
https://ドメイン名.ssl-lolipop.jp:443/省略/sources/main.cgi
https://ドメイン名.ssl-lolipop.jp:443/省略/sources/main.cgi/callback
試しましたが、全て
"Webhookが無効なHTTPステータスコードを返しました(期待されるステータスコードは200です)"
と表示されます。
よろしくお願いします。
追記:
一部省略しながらですがコードを載せます。
python
1#!/usr/local/bin/python3.4 2 print("Content-type: text/plain\n") 3 4# -*- coding: utf-8 -*- 5 6# Licensed under the Apache License, Version 2.0 (the "License"); you may 7# not use this file except in compliance with the License. You may obtain 8# a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15# License for the specific language governing permissions and limitations 16# under the License. 17 18from __future__ import unicode_literals 19 20import errno 21import os 22import sys 23import tempfile 24import requests 25import random 26 27from argparse import ArgumentParser 28 29from flask import Flask, request, abort 30 31from linebot import ( 32 LineBotApi, WebhookHandler 33) 34from linebot.exceptions import ( 35 InvalidSignatureError 36) 37from linebot.models import ( 38 MessageEvent, TextMessage, TextSendMessage, 39 SourceUser, SourceGroup, SourceRoom, 40 TemplateSendMessage, ConfirmTemplate, MessageTemplateAction, 41 ButtonsTemplate, ImageCarouselTemplate, ImageCarouselColumn, URITemplateAction, 42 PostbackTemplateAction, DatetimePickerTemplateAction, 43 CarouselTemplate, CarouselColumn, PostbackEvent, 44 StickerMessage, StickerSendMessage, LocationMessage, LocationSendMessage, 45 ImageMessage, VideoMessage, AudioMessage, FileMessage, 46 UnfollowEvent, FollowEvent, JoinEvent, LeaveEvent, BeaconEvent, 47 ImageSendMessage 48) 49 50import (省略) 51 52app = Flask(__name__) 53 54# get channel_secret and channel_access_token from your environment variable 55channel_secret = os.getenv('LINE_CHANNEL_SECRET', '(省略)') 56channel_access_token = os.getenv('LINE_CHANNEL_ACCESS_TOKEN', '(省略)') 57 58line_bot_api = LineBotApi(channel_access_token) 59handler = WebhookHandler(channel_secret) 60 61static_tmp_path = os.path.join(os.path.dirname(__file__), 'static', 'tmp') 62 63godparent = godparent.godparent() 64 65# function for create tmp dir for download content 66def make_static_tmp_dir(): 67 try: 68 os.makedirs(static_tmp_path) 69 except OSError as exc: 70 if exc.errno == errno.EEXIST and os.path.isdir(static_tmp_path): 71 pass 72 else: 73 raise 74 75@app.route("/callback", methods=['POST']) 76def callback(): 77 # get X-Line-Signature header value 78 signature = request.headers['X-Line-Signature'] 79 80 # get request body as text 81 body = request.get_data(as_text=True) 82 app.logger.info("Request body: " + body) 83 84 # handle webhook body 85 try: 86 handler.handle(body, signature) 87 except InvalidSignatureError: 88 abort(400) 89 90 return 'OK' 91 92@handler.add(MessageEvent, message=TextMessage) 93def handle_text_message(event): 94 95 response_message = (省略).update(event.message.text) 96 97 line_bot_api.reply_message( 98 event.reply_token, TextSendMessage(response_message)) 99 100 return 0 101 102if __name__ == "__main__": 103 arg_parser = ArgumentParser( 104 usage='Usage: python ' + __file__ + ' [--port <port>] [--help]' 105 ) 106 arg_parser.add_argument('-p', '--port', type=int, default=443, help='port') 107 arg_parser.add_argument('-d', '--debug', default=False, help='debug') 108 options = arg_parser.parse_args() 109 110 # create tmp dir for download content 111 make_static_tmp_dir() 112 113 app.run(debug=options.debug, port=options.port) 114
あなたの回答
tips
プレビュー