【问题标题】:how to extract specific info from Soap response in Python (pysimplesoap)如何从 Python 中的 Soap 响应中提取特定信息(pysimplesoap)
【发布时间】:2014-03-13 15:48:01
【问题描述】:

我开始使用 pysimplesoap 在 python 中编写代码。首先针对 Internet 上提供的服务进行测试。我一直在尝试解析 Soap 查询的结果。 我编码:

#!/usr/bin/python
from pysimplesoap.client import SoapClient
import pysimplesoap
import logging
logging.basicConfig()

client=SoapClient(wsdl="http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx?wsdl",trace=True)
response = client.VerifyEmail(email="a-valid-gmail-address@gmail.com",LicenseKey="?")
print response

我得到以下信息,这意味着 Soap 请求是肯定的:

{'VerifyEmailResult': {'GoodEmail': True, 'LastMailServer': u'gmail-smtp-in.l.google.com', 'ResponseText': u'Mail Server will accept email', 'ResponseCode': 3}}

我现在想从“response”中提取等于 True 的 GoodEmail 的值,并将其存储在名为“result”的变量中。 我尝试了各种事情,但没有成功。 我必须承认我对 Python 很陌生,希望有知识的人提供帮助!

【问题讨论】:

    标签: python soap xml-parsing pysimplesoap


    【解决方案1】:

    您得到的响应是 Python dict。您可以像这样访问GoodEmail 值:

    result = response['VerifyEmailResult']['GoodEmail']
    

    您可以在此处阅读有关 Python 数据类型的更多信息:http://docs.python.org/2/library/stdtypes.html

    【讨论】:

    • 谢谢。我以为我已经尝试过了。无论如何,这正是我想要的。我会评价你的答案,但我不能,因为我还没有 15 分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-13
    • 2022-12-04
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    相关资源
    最近更新 更多