前提・実現したいこと
apache上で起動させているFlaskで受信したメッセージをそのまま返すLinebotを作成しておりますが、
メッセージを受け取った際にエラーを出力してしまいます。
let'sEncriptでSSL環境化しております。
発生している問題・エラーメッセージ
[Tue Oct 16 16:19:36.979074 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] [2018-10-16 16:19:36,976] ERROR in app: Exception on /callback [POST] [Tue Oct 16 16:19:36.979111 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] Traceback (most recent call last): [Tue Oct 16 16:19:36.979114 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib64/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app [Tue Oct 16 16:19:36.979116 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] response = self.full_dispatch_request() [Tue Oct 16 16:19:36.979118 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib64/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request [Tue Oct 16 16:19:36.979121 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] rv = self.handle_user_exception(e) [Tue Oct 16 16:19:36.979122 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib64/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception [Tue Oct 16 16:19:36.979124 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] reraise(exc_type, exc_value, tb) [Tue Oct 16 16:19:36.979126 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib64/python3.6/site-packages/flask/_compat.py", line 35, in reraise [Tue Oct 16 16:19:36.979128 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] raise value [Tue Oct 16 16:19:36.979130 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib64/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request [Tue Oct 16 16:19:36.979132 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] rv = self.dispatch_request() [Tue Oct 16 16:19:36.979134 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib64/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request [Tue Oct 16 16:19:36.979136 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] return self.view_functions[rule.endpoint](**req.view_args) [Tue Oct 16 16:19:36.979138 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/var/www/flask/myapp.py", line 36, in callback [Tue Oct 16 16:19:36.979146 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] requests.post(LINE_ENDPOINT, headers=header, data=json.dumps(payload)) [Tue Oct 16 16:19:36.979148 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/requests/api.py", line 112, in post [Tue Oct 16 16:19:36.979150 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] return request('post', url, data=data, json=json, **kwargs) [Tue Oct 16 16:19:36.979152 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/requests/api.py", line 58, in request [Tue Oct 16 16:19:36.979154 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] return session.request(method=method, url=url, **kwargs) [Tue Oct 16 16:19:36.979163 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 512, in request [Tue Oct 16 16:19:36.979165 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] resp = self.send(prep, **send_kwargs) [Tue Oct 16 16:19:36.979167 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 622, in send [Tue Oct 16 16:19:36.979169 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] r = adapter.send(request, **kwargs) [Tue Oct 16 16:19:36.979171 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 445, in send [Tue Oct 16 16:19:36.979172 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] timeout=timeout [Tue Oct 16 16:19:36.979174 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen [Tue Oct 16 16:19:36.979176 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] chunked=chunked) [Tue Oct 16 16:19:36.979178 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request [Tue Oct 16 16:19:36.979180 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] self._validate_conn(conn) [Tue Oct 16 16:19:36.979182 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn [Tue Oct 16 16:19:36.979184 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] conn.connect() [Tue Oct 16 16:19:36.979186 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 344, in connect [Tue Oct 16 16:19:36.979188 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] cert_reqs=resolve_cert_reqs(self.cert_reqs), [Tue Oct 16 16:19:36.979189 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 297, in create_urllib3_context [Tue Oct 16 16:19:36.979191 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] context.verify_mode = cert_reqs [Tue Oct 16 16:19:36.979193 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 403, in verify_mode [Tue Oct 16 16:19:36.979195 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] _verify_callback [Tue Oct 16 16:19:36.979197 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1108, in set_verify [Tue Oct 16 16:19:36.979199 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] self._verify_helper = _VerifyHelper(callback) [Tue Oct 16 16:19:36.979201 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] File "/usr/lib/python3.6/site-packages/OpenSSL/SSL.py", line 333, in __init__ [Tue Oct 16 16:19:36.979203 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] "int (*)(int, X509_STORE_CTX *)", wrapper) [Tue Oct 16 16:19:36.979208 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430] SystemError: <built-in method callback of CompiledFFI object at 0x7f7ecc38b130> returned NULL without setting an error [Tue Oct 16 16:19:36.979227 2018] [wsgi:error] [pid 1713] [client 203.104.146.156:41430]
該当のソースコード
python
1# coding: utf-8↲ 2from flask import Flask↲ 3from flask import request↲ 4import requests↲ 5import json↲ 6↲ 7CHANNEL_ACCESS_TOKEN='取得したアクセストークン'↲ 8↲ 9LINE_ENDPOINT = 'https://api.line.me/v2/bot/message/reply'↲ 10↲ 11app = Flask(__name__)↲ 12↲ 13@app.route("/callback", methods=['POST'])↲ 14def callback():↲ 15 for event in request.json['events']:↲ 16 messages = [↲ 17 {↲ 18 'type': 'text',↲ 19 'text': event['message']['text'],↲ 20 }↲ 21 ]↲ 22 print (messages,event['replyToken'])↲ 23↲ 24 header = {↲ 25 "Content-Type": "application/json",↲ 26 "Authorization": "Bearer " + CHANNEL_ACCESS_TOKEN↲ 27 }↲ 28 payload = {↲ 29 "replyToken": event['replyToken'],↲ 30 "messages": messages,↲ 31 }↲ 32 33 print(LINE_ENDPOINT)↲ 34 requests.post(LINE_ENDPOINT, headers=header, data=json.dumps(payload))↲ 35 return '{}', 200↲ 36if __name__ == "__main__":
試したこと
requests.postで落ちているように見えたので、requests.postをコメントアウトしたところwebhook urlの接続確認をすることはできました。
またwebhookを使用せずにプッシュメッセージを送信するスクリプトを実行したところこちらは正常に送信できました。
環境
[Apache]
Server version: Apache/2.4.6 (CentOS)
Server built: Jun 27 2018 13:48:59
[OS]
CentOS Linux release 7.5.1804 (Core)
よろしくおねがいします。
あなたの回答
tips
プレビュー