简体   繁体   中英

soaplib problems with XML characters in string payload

I've created a simple SOAP web service using soaplib and run into an issue in which SOAP parameters sent including ampersands or angle brackets are ignored, even when escaped.

Whether the method is set up to accept a primitive string or a primitive of type 'any', any of those characters introduced result in a webfault (using suds) of this type:

suds.WebFault: Server raised fault: 'my_method() takes exactly 2 arguments (1 given)'

For now, here's the method, having removing addition code used to store the result:

@soapmethod(soap_types.String, _returns=soap_types.Boolean)
def my_method_(self, sample):
    return True

Calling this method with any simple string works just fine, eg in suds,

suds_object.service.my_method('Hello World')

results in "true". But add in any ampersand or angle bracket, eg

suds_object.service.my_method('Hello & World')

and the exception is raised. With logging turned on I can see that suds is escaping these characters. So far I've been able to figure out that the problem is not down at the primitive level and I can't figure out where or what the problem is. It makes it rather difficult to send XML payloads through the service.

The class used is a subclass of SimpleWSGISoapApp, and the method is served as a Django view. I noticed that when attempting to use the Hello World example using the soaplib client library that it worked just fine.

I had problems with "easier" soap libs in python (esp. suds). I had a question a while ago that led me to use soapPy instead, and a problem similar to yours just vanished.

Suds + JIRA = SAXException

That question also had good suggestions on using, eg, wireshark (or google "soap debugger") to see what was happening at a lower level.

The problem was absolutely NOT soaplib, but the Django code. That code was reading request.POST.items() for some reason which chopped up the SOAP request at any special character (eg =, &, >). Switched to soaplib trunk , updated the Django code , and that solved both the arguments error raised and related Unicode ValueErrors that lxml was raising.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM