Search code examples
pythonsoapxml-parsingpysimplesoap

how to extract specific info from Soap response in Python (pysimplesoap)


I'm starting to code in python using pysimplesoap. Testing first against a service available on Internet. I'm stuck trying to parse the result of the Soap query. I coded:

#!/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="[email protected]",LicenseKey="?")
print response

I get the following which means the Soap request was positive:

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

I now want to extract the value of GoodEmail which is equal to True from "response" and store it in a variable named "result". I tried various things, without success. I must admit I'm very new to Python, and would appreciate help from a knowledgeable person!


Solution

  • What you get as the response is a Python dict. You can access the GoodEmail value like that:

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

    You can read more about Python data types here: http://docs.python.org/2/library/stdtypes.html