You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Python的Twilio Chatbot无响应及12200 Schema验证警告求助

问题排查与解决
  • 核心原因:你的Flask接口默认返回text/html类型的内容,但Twilio要求接收text/xml格式的响应,这会导致Twilio无法正确解析返回的TwiML,触发12200 schema验证警告,最终不发送回复。
  • 修复步骤:
    1. 使用Flask的make_response方法,明确设置响应的Content-Type为text/xml。
    2. 调整后的完整代码:
from flask import Flask, request, make_response
from twilio.twiml.messaging_response import MessagingResponse

app = Flask(__name__)    

@app.route('/sms', methods=['POST'])
def sms():            
    from_number = request.form['From']
    to_number = request.form['To']
    body = request.form['Body']
    
    resp = MessagingResponse()
    resp.message("The Robots are coming! Head for the hills!")
    
    # 创建响应并指定内容类型
    response = make_response(str(resp))
    response.headers['Content-Type'] = 'text/xml'
    return response

if __name__ == '__main__':
    app.run()
  • 额外检查项:
    • 确认Flask服务已通过内网穿透工具(如ngrok)暴露到公网,Twilio需要能正常访问你的/sms接口。
    • 核对Twilio控制台中Webhook的配置,确保地址正确且请求方法设置为POST。

内容的提问来源于stack exchange,提问作者Kavya Shree

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 22:25:00