我試圖解析來自服務器的SOAP
響應。我是SOAP
的全新新人,並且是使用HTTP
/HTTPS
進行溝通的新手。我在Ubuntu 12.04上使用Python 2.7。在Python中解析SOAP響應
看起來像SOAP
非常像XML
。但是,我似乎無法解析它。我試圖使用ElementTree
,但不斷收到錯誤。從搜索中我可以得出結論,SOAP
標籤可能存在問題。 (我可以在這裏...讓我知道如果我是。)
所以,這裏是一個SOAP
消息的例子,我試圖做的解析它(這是一個實際的來自Link Point Gateway的服務器響應,以防相關)。
import xml.etree.ElementTree as ET
soap_string = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><fdggwsapi:FDGGWSApiOrderResponse xmlns:fdggwsapi="http://secure.linkpt.net/fdggwsapi/schemas_us/fdggwsapi"><fdggwsapi:CommercialServiceProvider/><fdggwsapi:TransactionTime>Wed Jul 25 10:26:40 2012</fdggwsapi:TransactionTime><fdggwsapi:TransactionID/><fdggwsapi:ProcessorReferenceNumber/><fdggwsapi:ProcessorResponseMessage/><fdggwsapi:ErrorMessage>SGS-002303: Invalid credit card number.</fdggwsapi:ErrorMessage><fdggwsapi:OrderId>1</fdggwsapi:OrderId><fdggwsapi:ApprovalCode/><fdggwsapi:AVSResponse/><fdggwsapi:TDate/><fdggwsapi:TransactionResult>FAILED</fdggwsapi:TransactionResult><fdggwsapi:ProcessorResponseCode/><fdggwsapi:ProcessorApprovalCode/><fdggwsapi:CalculatedTax/><fdggwsapi:CalculatedShipping/><fdggwsapi:TransactionScore/><fdggwsapi:FraudAction/><fdggwsapi:AuthenticationResponseCode/></fdggwsapi:FDGGWSApiOrderResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>'
targetTree = ET.fromstring(soap_string)
我們得到以下錯誤:
unbound prefix: line 1, column 0
從另一個計算器post我已經得出結論,SOAP-ENV:Body
可能導致一個命名空間的問題。 (我可能是錯的。)
我已經做了其他搜索找到一個很好的解決方案,解析SOAP
,但其中大多數是從3年以上。看來suds非常值得推薦。在我走得太遠之前,我想獲得「更新」的建議。
任何人都可以推薦一個固定的(和簡單的)方法來解析SOAP
響應,就像我上面收到的響應一樣嗎?如果你能提供一個簡單的例子讓我開始(如上所述,我完全是SOAP
的新手),這將不勝感激。
對不起,我沒有注意到,並忘記更新問題。 – Rico 2012-07-25 21:56:24
編輯的問題和例子適用於我。我沒有得到這個錯誤...有什麼遺漏嗎? – Tisho 2012-07-25 21:58:17
我不這麼認爲......我一定錯過了第一個信封。 = -/ – Rico 2012-07-25 22:06:44