使用Pli发出的在Django IVR中不工作的POST请求

2024-09-28 03:17:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个交互式语音应答系统,我用Plivo来制作IVR。我跟踪了这个用Python Flask编写的示例应用程序。下面是制作示例应用程序的链接。在

https://www.plivo.com/docs/getting-started/phone-menu-app/

这是存储库和python flask中名为ivr()的视图方法 https://github.com/Chitrank-Dixit/phone-ivr-python/blob/master/app.py#L23

您也可以查看代码

@app.route('/response/ivr/', methods=['GET', 'POST'])
def ivr():
    response = plivoxml.Response()
    if request.method == 'GET':
        # GetDigit XML Docs - http://plivo.com/docs/xml/getdigits/
        getdigits_action_url = url_for('ivr', _external=True)
        getDigits = plivoxml.GetDigits(action=getdigits_action_url,
                                       method='POST', timeout=7, numDigits=1,
                                       retries=1)

        getDigits.addSpeak(IVR_MESSAGE)
        response.add(getDigits)
        response.addSpeak(NO_INPUT_MESSAGE)

        return Response(str(response), mimetype='text/xml')

    elif request.method == 'POST':
        digit = request.form.get('Digits')

        if digit == "1":
            # Fetch a random joke using the Reddit API.
            joke = joke_from_reddit()
            response.addSpeak(joke)
        elif digit == "2":
            # Listen to a song
            response.addPlay(PLIVO_SONG)
        else:
            response.addSpeak(WRONG_INPUT_MESSAGE)

        return Response(str(response), mimetype='text/xml')

我只需要在我的Django IVR中有同样的行为。我只是用pythondjango实现所有的东西。 下面是指向存储库的链接,上面的ivr()方法重命名为ivr_sample(),在pythondjango中实现。在

https://github.com/Chitrank-Dixit/phone-ivr-python/blob/master/app.py#L23

这是密码

^{pr2}$

我可以在手机上收听GET请求,但当我键入0或1时,我就可以收听所需的消息。电话挂断,然后连接关闭。这意味着ivr_sample()方法正在接受GET响应,但在我的例子中它没有运行POST响应。基于烧瓶的应用程序运行良好,没有任何问题。在

Django需要保护。所以我使用了django文档中指定的csrf decorator。 以下是链接:https://docs.djangoproject.com/en/1.8/ref/csrf/

但IVR仍然不起作用。在

最糟糕的是我们不能在本地测试。所以我得修改一下,在网上测试一下。如果有人在plivo之前用pythondjango制作ivr。请告诉我我哪里错了。在


Tags: 方法httpscomappdocsget链接response
1条回答
网友
1楼 · 发布于 2024-09-28 03:17:17

好吧,这只是一个小的解决办法,我尝试了所有的csrf装饰。在名为ivr_sample的视图中。在@csrf_protect的地方,我只需要使用@csrf_exempt。现在一切都很顺利。在

相关问题 更多 >

    热门问题