现在我有一个程序,它接收SMS消息,发布消息的正文,然后将SMS转发到另一个号码。然而,我从Twilio收到了一个关于“方案验证”的错误。代码完全正常工作,但是我想修复这个错误。
最初,我有以下代码:
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 (仅相关部分)
@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.
我该如何解决这个问题呢?
发布于 2016-11-17 04:43:40
我是Twilio的布道者。
在响应对消息请求<Say>
的请求时,<Say>
不是可包括的有效TwiML谓词。它只对语音请求有效。
如果您想要将消息发送回发送文本消息给Twilio的人,请使用<Message>
动词。
resp = twilio.twiml.Response()
resp.message(message)
另外,看起来您正在发送TwiML作为新的出站短消息的消息。我认为你可以用Body参数来代替它。
client.messages.create(to=ePhone,from_=tPhone,body=TheMessage)
希望这能有所帮助。
https://stackoverflow.com/questions/40641197
复制相似问题