Created
March 13, 2013 15:44
-
-
Save smartkiwi/5153378 to your computer and use it in GitHub Desktop.
Example of using MessagePlugin to prevent suds from parsing response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import suds | |
__author__ = 'Volodymyr Vladymyrov: [email protected]' | |
__doc__ = "Example of using MessagePlugin to prevent suds from parsing response" | |
class PayloadInterceptor(suds.plugin.MessagePlugin): | |
def __init__(self, *args, **kwargs): | |
self.last_payload = None | |
def received(self, context): | |
#recieved xml as a string | |
print "%s bytes recieved" % len(context.reply) | |
self.last_payload = context.reply | |
#clean up reply to prevent parsing | |
context.reply = "" | |
return context | |
if __name__=='__main__': | |
wsurl = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL" | |
payload_interceptor = PayloadInterceptor() | |
client = suds.client.Client(wsurl, plugins=[payload_interceptor]) | |
print client | |
res = client.service.CapitalCity("NL") | |
print "received %s bytes" % len(payload_interceptor.last_payload) | |
print "parsed result: %s" % res | |
print "response payload: %s" % payload_interceptor.last_payload | |
""" | |
Produce output: | |
Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913 | |
Service ( CountryInfoService ) tns="http://www.oorsprong.org/websamples.countryinfo" | |
Prefixes (1) | |
ns0 = "http://www.oorsprong.org/websamples.countryinfo" | |
Ports (1): | |
(CountryInfoServiceSoap) | |
Methods (21): | |
CapitalCity(xs:string sCountryISOCode, ) | |
CountriesUsingCurrency(xs:string sISOCurrencyCode, ) | |
CountryCurrency(xs:string sCountryISOCode, ) | |
CountryFlag(xs:string sCountryISOCode, ) | |
CountryISOCode(xs:string sCountryName, ) | |
CountryIntPhoneCode(xs:string sCountryISOCode, ) | |
CountryName(xs:string sCountryISOCode, ) | |
CurrencyName(xs:string sCurrencyISOCode, ) | |
FullCountryInfo(xs:string sCountryISOCode, ) | |
FullCountryInfoAllCountries() | |
LanguageISOCode(xs:string sLanguageName, ) | |
LanguageName(xs:string sISOCode, ) | |
ListOfContinentsByCode() | |
ListOfContinentsByName() | |
ListOfCountryNamesByCode() | |
ListOfCountryNamesByName() | |
ListOfCountryNamesGroupedByContinent() | |
ListOfCurrenciesByCode() | |
ListOfCurrenciesByName() | |
ListOfLanguagesByCode() | |
ListOfLanguagesByName() | |
Types (12): | |
ArrayOftContinent | |
ArrayOftCountryCodeAndName | |
ArrayOftCountryCodeAndNameGroupedByContinent | |
ArrayOftCountryInfo | |
ArrayOftCurrency | |
ArrayOftLanguage | |
tContinent | |
tCountryCodeAndName | |
tCountryCodeAndNameGroupedByContinent | |
tCountryInfo | |
tCurrency | |
tLanguage | |
336 bytes recieved | |
received 336 bytes | |
parsed result: None | |
response payload: <?xml version="1.0" encoding="utf-8"?> | |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> | |
<soap:Body> | |
<m:CapitalCityResponse xmlns:m="http://www.oorsprong.org/websamples.countryinfo"> | |
<m:CapitalCityResult>Amsterdam</m:CapitalCityResult> | |
</m:CapitalCityResponse> | |
</soap:Body> | |
</soap:Envelope> | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment