2016-11-16 37 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 –