Leo
Leo

Reputation: 1809

How to get a SOAP body by using SOAPpy?

I try to call a method using a SOAP request by using SOAPpy on Python 2.7.5 The method is called GetCursOnDate and returns exchange rates. It takes a datetime parameter.

I'm using the following code:

from SOAPpy import WSDL
from SOAPpy import Types

# you can download this and use it locally for better performance
wsdl = "http://www.cbr.ru/DailyInfoWebServ/DailyInfo.asmx?wsdl"
namespace = "http://web.cbr.ru/"
input = Types.dateType(name = (namespace, "On_date"))

proxy = WSDL.Proxy(wsdl, namespace = namespace)
proxy.soapproxy.config.debug = 1

proxy.GetCursOnDate(input)

The problem is how to get a body of the SOAP response with the exchange rates

Upvotes: 2

Views: 857

Answers (1)

ndpu
ndpu

Reputation: 22561

If you want to look at it (SOAPpy request/response body) in console, add this lines:

proxy.soapproxy.config.dumpSOAPOut = 1
proxy.soapproxy.config.dumpSOAPIn = 1

and then call:

proxy.GetCursOnDate(input)

update: Cant get it to work with SOAPpy, always get an empty result. I think the problem is that the schema references a type defined in the schema namespace="http://www.w3.org/2001/XMLSchema" but does not import it (without doctor param suds Client throw this exception: suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'). Try it with suds client:

from suds.client import Client
from suds.xsd.doctor import ImportDoctor, Import
import datetime

imp = Import('http://www.w3.org/2001/XMLSchema') # the schema to import.
imp.filter.add('http://web.cbr.ru/')             # the schema to import into.
d = ImportDoctor(imp)
s = Client("http://www.cbr.ru/DailyInfoWebServ/DailyInfo.asmx?wsdl", doctor=d)
result = s.service.GetCursOnDate(datetime.datetime.now())

Upvotes: 5

Related Questions