首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Twilio/Python - 12200架构验证警告

Twilio/Python - 12200架构验证警告
EN

Stack Overflow用户
提问于 2016-11-17 03:58:21
回答 1查看 541关注 0票数 0

现在我有一个程序,它接收SMS消息,发布消息的正文,然后将SMS转发到另一个号码。然而,我从Twilio收到了一个关于“方案验证”的错误。代码完全正常工作,但是我想修复这个错误。

最初,我有以下代码:

代码语言:javascript
运行
复制
import RUAlertsTwilioWEBSERVER
import twilio.twiml
import time
import praw

from flask import Flask, request, redirect
from twilio.rest import TwilioRestClient
from passwords import *
from twilio import twiml

def login():
    r = praw.Reddit(app_ua)
    r.set_oauth_app_info(app_id, app_secret, app_uri)
    r.refresh_access_information(app_refresh)
    return r

r=RUAlertsTwilioWEBSERVER.login()
client = TwilioRestClient(account_sid, auth_token)

app = Flask(__name__)

@app.route("/", methods=['GET', 'POST'])
def AlertService():
    TheMessage=request.form.get("Body")
    if (TheMessage != None):
        print(TheMessage)
        client.messages.create(to=ePhone,from_=tPhone,body=str(TheMessage))
        r.submit(*submit to reddit code*)
    return str(TheMessage)

if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0")

Twilio调试器提供了Content is not allowed in prolog. Warning - 12200 Schema validation warning The provided XML does not conform to the Twilio Markup XML schema.

我试图通过将代码更改为以下代码来获取发布所需的XML (仅相关部分)

代码语言:javascript
运行
复制
@app.route("/", methods=['GET', 'POST'])
def AlertService():
    TheMessage=request.form.get("Body")
    if (TheMessage != None):
        print(TheMessage)
        resp = twiml.Response()
        XML = resp.say(TheMessage)
        client.messages.create(to=ePhone,from_=tPhone,body=XML)
        r.submit(*submit to reddit code*)
        return str(resp)
    return str(TheMessage)

此代码不起作用,因此我将body=XML更改为body=str(XML)。但是,现在它只是将XML作为正文发送,我收到了错误:cvc-complex-type.2.4.a: Invalid content was found starting with element 'Say'. One of '{Sms, Message, Redirect}' is expected. Warning - 12200 Schema validation warning The provided XML does not conform to the Twilio Markup XML schema.

我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

发布于 2016-11-17 04:43:40

我是Twilio的布道者。

在响应对消息请求<Say>的请求时,<Say>不是可包括的有效TwiML谓词。它只对语音请求有效。

如果您想要将消息发送回发送文本消息给Twilio的人,请使用<Message>动词。

代码语言:javascript
运行
复制
resp = twilio.twiml.Response()
resp.message(message)

另外,看起来您正在发送TwiML作为新的出站短消息的消息。我认为你可以用Body参数来代替它。

代码语言:javascript
运行
复制
client.messages.create(to=ePhone,from_=tPhone,body=TheMessage)

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40641197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档