Struct question (SOAPpy095)

Cayce Ullman Cayce at actzero.com
Mon Jun 4 15:21:46 EDT 2001


Tom wrote:
> I am using Python 2.1, with SOAPpy095, with the Radio Userland SOAP
> server. Here is some code I have:
> 
> ################
> import SOAP
> import urlparse
> import string
> import types
> import pprint
> 
> soapServer = SOAP.SOAPProxy(urlparse.urljoin(baseServerURL, 
> examplesDir))
> quote = soapServer.getStockPrice(symbol="AAPL")
> print quote
> 
> ################
> 
> This results in:
> 
> <SOAP.Struct Result at 41566444>
> 
> My question is, what is this and how do I access it? Forgive me, but
> I'm new to Python.
> 
> Tom.

SOAP.py attempts to guess when to bubble up a value.  For instance, this
response :

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/1999/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
<soap:Body>
<n:getQuoteResponse xmlns:n='urn:xmethods-delayed-quotes'>
<Result xsi:type='xsd:float'>114.25</Result>
</n:getQuoteResponse>
</soap:Body>
</soap:Envelope> 

will just retrun the float : 114.25 

But this response : 

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/1999/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
<soap:Body>
<n:getQuoteResponse xmlns:n='urn:xmethods-delayed-quotes'>
<Symbol xsi:type='xsd:string'>AAPL</Symbol>
<Price xsi:type='xsd:float'>114.25</Price>
</n:getQuoteResponse>
</soap:Body>
</soap:Envelope> 

Will return the getQuoteResponse struct, because the response contains
multiple values and must give you a way to get all of them.


I'm not sure what the service you are calling returns as you have not
provided the endpoint info, but my guess is you are getting more than just
the price back.

Add this line to the end of your code : 
print dir(quote)

I suspect the actual price will be an attribute of the struct.  

There is ways to force SOAP.py calls to return you everything and make no
guesses for consistent behavior, but it has been our experience that running
the default way is more convenient.

Cayce








More information about the Python-list mailing list