首页 > 解决方案 > 如何修复 Twilio 可编程短信(WhatsApp)中的“11200 HTTP 检索失败错误”

问题描述

我想了解导致 11200 HTTP 检索错误的原因是什么?我已将 POST 请求的响应发送到 DialogFlow,它不应该处理将此响应发送到 Twilio 吗?

这是我到目前为止所做的

我已经设置了一个本地 python 服务器,并使用 ngrok 公开了本地主机。这个想法是使用 Twilio Programmable SMS 创建一个天气机器人。发给 Twilio 的初始消息被转发到 DialogFlow,然后它向我的 python 服务器发送一个 post 请求。然后我处理这个请求,并从 OpenWeatherMap API 中获取相关的天气信息。对于服务器开发人员来说相对较新,我假设我需要将 DialogFlow 指南中提到的具有正确结构的响应(例如,包括fulfillmentText 参数)发送回DialogFlow,然后它应该将响应发送给Twilio,并且应该显示在我的 WhatsApp Twilio 沙盒上。** 但是我得到的是 Twilio Degugger 中的 11200 HTTP 检索失败错误,我想了解我是否'

我曾使用 PHP 服务器尝试过相同的程序,它运行得非常好。我只是想使用 Python 服务器重新创建程序,因为我暂时更喜欢使用它。

// 做 webhook.py 的 post 方法

def do_POST(self):
    try:
        content_len = int(self.headers.get('Content-Length'))
        post_body = self.rfile.read(content_len)

        requestjson = json.loads(post_body)
        city = requestjson["queryResult"]["parameters"]["geo-city"]
        if city:
            print(city)
            info = getWeatherInformation(city)
            print(info) # Prints temp in city and weather condition successfully
            self.send_response(200)
            self.wfile.write(info.encode(encoding = "utf_8"))

从 getWeatherInformation 以下列方式返回 info 变量

res = {"fulfillmentText":response}
info = json.dumps(res)
return info

墨尔本市的控制台调试语句

Web Server running on port: 8080
Melbourne
{"fulfillmentText": "It is 31.29 degrees with clear sky"}
127.0.0.1 - - [27/Jan/2019 23:00:34] "POST /webhook.py HTTP/1.1" 200 -

博客文章中的 PHP Webhook 代码可以正常工作

/*向Dialogflow发送天气数据响应的部分代码*/

function sendFulfillmentResponse($temperature, $weatherDescription)
{
   $response = "It is $temperature degrees with $weatherDescription";

   $fulfillment = array(
       "fulfillmentText" => $response
   );

   echo(json_encode($fulfillment));
}

我希望在 WhatsApp 上看到来自 Twilio Sandbox 帐户的响应,类似于我使用 PHP 创建服务器时的响应。相反,我在 Twilio 调试器中得到 11200 错误,但在服务器终端中没有错误。

标签: pythonhttpwebservertwiliodialogflow-es

解决方案


推荐阅读