DjangoとApacheを用いてLINE@にBOTを作成しています。環境を整えwebhook(アドレスは<domain>/callback)を認識させる段まで来ましたが、タイトル通りのエラーが出てしまいます。以下私の環境、確認した現象ならびにソースコードなどです。
・環境
ArchLinux
Apache 2.4.33
Django 2.0.5
SSL証明書Let's encrypt由来のものを使用
・確認した現象
アクセスログにはLINEからと思われる通信記録がありませんでした。しかし、httpsでfirefoxを使用したアクセスはでき、生存信号は発しています。
・ソースなど(httpd.conf,views.py,url.py)
//httpd.conf(一部省略) #WSGIScriptAlias / /srv/http/trippp/trippp/wsgi.py #WSGIPythonPath /srv/http/trippp #Alias /static /srv/http/static #<Directory /srv/http/trippp/trippp> # AllowOverride None # <Files wsgi.py> # Require all granted # </Files> #</Directory> #<Directory /srv/http/static> #Require all granted #</Directory> Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" <Directory "/var/lib/letsencrypt/"> AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory>
//django views.py from django.shortcuts import render from django.http.response import HttpResponse import os import json import random import requests from django.http import JsonResponse from django.views.generic import View import urllib REPLY_ENDPOINT = 'https://api.line.me/v2/bot/message/reply' header = { "Content-Type": "application/json", "Authorization": "SNhJEyedwz7m8O2Bl0oZ5OUnVFrYJMwi/riT0EdZxUtwLpg/OKFbKr27UVdLZ7P7nEQp0YufLtriNnE1CVo2tmSRidh/yY/69rmnnYoMdFX7oMz/8g9hiSFZOzwqNd0+TLqhi3UzOf03BQ3LC4bTiwdB04t89/1O/w1cDnyilFU=" } def dispose(events): global header print('This is dispose request') for event in events: reply_token = event['replyToken'] event_type = event['type'] user_id = event['source']['userId'] response_to_talk(reply_token, event) def response_to_talk(reply_token, event): global header print("enter response to talk") payload = { "replyToken":reply_token, "messages": { "type":"text", "text": event['message']['text'] } } req = requests.post(REPLY_ENDPOINT, headers=header, data=json.dumps(payload)) class ViewSet(View): global header http_method_names = ['get', 'post'] def get(self, *args, **kwargs): return JsonResponse({'Successfully': 'Connected!'}) def post(self, request, *args, **kwargs): dispose(json.loads(request.body.decode("utf-8"))['events']) return JsonResponse({'': ''})
//url.py from django.contrib import admin from django.urls import path from django.conf.urls import url from core.views import ViewSet urlpatterns = [ path('admin/', admin.site.urls), url(r'^callback$', ViewSet.as_view()), ]
足りない情報等あれば大変恐縮ですが、指摘していただけると幸いです。以上よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。