iT邦幫忙

0

LINE BOT (django)Azure 求救

  • 分享至 

  • xImage

己經確認透過GITHUB 部署到AZURE,帳號也因此開了"付費"選項,BOT SERVICE 選了F0
還是出現HTTP 不接受的問題?!?!
https://ithelp.ithome.com.tw/upload/images/20200709/201250652JD1lCakgy.png
//這個程式是先引用書上的來測試再來慢慢改,本地測試沒有什麼狀況....
VIEWS.py

from django.conf import settings
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden
from django.views.decorators.csrf import csrf_exempt

from linebot import LineBotApi, WebhookParser
from linebot.exceptions import InvalidSignatureError, LineBotApiError
from linebot.models import MessageEvent, TextSendMessage

line_bot_api = LineBotApi(settings.LINE_CHANNEL_ACCESS_TOKEN)
parser = WebhookParser(settings.LINE_CHANNEL_SECRET)


@csrf_exempt
def callback(request):
    if request.method == 'POST':
        signature = request.META['HTTP_X_LINE_SIGNATURE']
        body = request.body.decode('utf-8')

        try:
            events = parser.parse(body, signature)
        except InvalidSignatureError:
            return HttpResponseForbidden()
        except LineBotApiError:
            return HttpResponseBadRequest()

        for event in events:
            if isinstance(event, MessageEvent):
                line_bot_api.reply_message(event.reply_token,TextSendMessage(text=event.message.text))

        return HttpResponse()
    else:
        return HttpResponseBadRequest()

urls.py

"""botpandas URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from botapi import views

urlpatterns = [
    url('^callback', views.callback),
    #path('callback/', callback),
    path(r'admin/', admin.site.urls),
]

Victor iT邦新手 2 級 ‧ 2020-07-09 09:04:27 檢舉
http://blog.e-happy.com.tw/django2-0-%E4%BB%A5-path-%E5%87%BD%E5%BC%8F%E8%A8%AD%E5%AE%9A-urlpatterns/

沒寫過!幫你查到的!不知道是不是提供你參考
KYCPG iT邦新手 4 級 ‧ 2020-07-09 10:10:57 檢舉
我猜也是正則表示的問題...
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答