質問編集履歴

2

コードの該当行を分かりやすくするために行番号を入れました

2019/08/07 08:17

投稿

sa-mon
sa-mon

スコア8

test CHANGED
File without changes
test CHANGED
@@ -30,79 +30,77 @@
30
30
 
31
31
  ```Django
32
32
 
33
- from django.shortcuts import render
33
+ 1 from django.shortcuts import render
34
34
 
35
- from django.http import HttpResponseForbidden, HttpResponse
35
+ 2 from django.http import HttpResponseForbidden, HttpResponse
36
36
 
37
- from django.views.decorators.csrf import csrf_exempt
37
+ 3 from django.views.decorators.csrf import csrf_exempt
38
38
 
39
- from linebot import (LineBotApi, WebhookHandler)
39
+ 4 from linebot import (LineBotApi, WebhookHandler)
40
40
 
41
- from linebot.exceptions import (InvalidSignatureError)
41
+ 5 from linebot.exceptions import (InvalidSignatureError)
42
42
 
43
- from linebot.models import (
43
+ 6 from linebot.models import (
44
44
 
45
- MessageEvent,
45
+ 7 MessageEvent,
46
46
 
47
- TextMessage,
47
+ 8 TextMessage,
48
48
 
49
- TextSendMessage,
49
+ 9 TextSendMessage,
50
50
 
51
- )
51
+ 10 )
52
52
 
53
- import os
53
+ 11 import os
54
54
 
55
+ 12
55
56
 
57
+ 13 YOUR_CHANNEL_ACCESS_TOKEN = os.environ["YOUR_CHANNEL_ACCESS_TOKEN"]
56
58
 
57
- YOUR_CHANNEL_ACCESS_TOKEN = os.environ["YOUR_CHANNEL_ACCESS_TOKEN"]
59
+ 14 YOUR_CHANNEL_SECRET = os.environ["YOUR_CHANNEL_SECRET"]
58
60
 
59
- YOUR_CHANNEL_SECRET = os.environ["YOUR_CHANNEL_SECRET"]
61
+ 15
60
62
 
63
+ 16 line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN)
61
64
 
65
+ 17 handler = WebhookHandler(YOUR_CHANNEL_SECRET)
62
66
 
63
- line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN)
67
+ 18
64
68
 
65
- handler = WebhookHandler(YOUR_CHANNEL_SECRET)
69
+ 19
66
70
 
71
+ 20 @csrf_exempt
67
72
 
73
+ 21 def callback(request):
68
74
 
75
+ 22 signature = request.META['HTTP_X_LINE_SIGNATURE']
69
76
 
77
+ 23 body = request.body.decode('utf-8')
70
78
 
71
- @csrf_exempt
79
+ 24 try:
72
80
 
81
+ 25 handler.handle(body, signature)
73
82
 
83
+ 26 except InvalidSignatureError:
74
84
 
75
- def callback(request):
85
+ 27 HttpResponseForbidden()
76
86
 
77
- signature = request.META['HTTP_X_LINE_SIGNATURE']
87
+ 28 return HttpResponse('OK', status=200)
78
88
 
79
- body = request.body.decode('utf-8')
89
+ 29
80
90
 
81
- try:
91
+ 30
82
92
 
83
- handler.handle(body, signature)
93
+ 31 # オウム返し
84
94
 
85
- except InvalidSignatureError:
95
+ 32 @handler.add(MessageEvent, message=TextMessage)
86
96
 
87
- HttpResponseForbidden()
97
+ 33 def handle_text_message(event):
88
98
 
89
- return HttpResponse('OK', status=200)
99
+ 34 line_bot_api.reply_message(event.reply_token,
90
100
 
101
+ 35 TextSendMessage(text=event.message.text))
91
102
 
92
-
93
-
94
-
95
- # オウム返し
103
+ 36
96
-
97
- @handler.add(MessageEvent, message=TextMessage)
98
-
99
- def handle_text_message(event):
100
-
101
- line_bot_api.reply_message(event.reply_token,
102
-
103
- TextSendMessage(text=event.message.text))
104
-
105
-
106
104
 
107
105
  ```
108
106
 

1

見返したときなぜかエラーメッセージとソースコードの記載が違ったため記載

2019/08/07 08:17

投稿

sa-mon
sa-mon

スコア8

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
 
4
4
 
5
- Djangoを使ってlinebot 開発中syntaxerrorが発生してdefについて聞かれたがどこを直せばいいかわからず困っています
5
+ Djangoを使ってlinebot 開発中syntaxerrorが発生してdefについて聞かれた
6
+
7
+ ソースコードを見るとエラーログと違っていることが分かった
6
8
 
7
9
  ### 発生している問題・エラーメッセージ
8
10
 
@@ -108,9 +110,7 @@
108
110
 
109
111
  ### 試したこと
110
112
 
111
-
113
+ ソースコードではcallbodyになっているのにエラーコードではcallbbodyになっていたためソースコード側をもう一度書き直して保存したが結果が反映されなかった
112
-
113
-
114
114
 
115
115
 
116
116