2016-11-16 39 views
0

现在我有一个程序接收一条SMS消息,发布消息正文,然后将SMS转发给另一个号码。但是,我收到Twilio关于“Scheme验证”的错误。代码的功能与它应该完全一样,但我想修复错误。Twilio/Python - 12200架构验证警告

起初,我有以下代码:

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=XMLbody=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.

如何解决此问题?

回答

0

Twilio福音传教士在这里。

<Say>不是响应于对消息请求​​URL的请求而包括的有效TwiML动词。它仅对语音请求有效。

如果您想发送消息给发送短信给Twilio的人,请使用<Message>动词。

resp = twilio.twiml.Response() 
resp.message(message) 

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

client.messages.create(to=ePhone,from_=tPhone,body=TheMessage) 

希望有帮助。

+0

对不起,我不清楚这一点。我想将发送给Twilio的SMS正文转发给另一个第三个号码(不是发件人或Twilio号码)。 当我使用“说”只是为了获得XML格式。 这段代码'client.messages.create(to = ePhone,from_ = tPhone,body = TheMessage)'有效,但我仍然从调试器中得到错误。 –

+0

@DevinRader你能检查我的问题吗?谢谢http://stackoverflow.com/questions/43367898/twilio-quick-start-project-is-not-working –