Search code examples
djangoweb-servicessoaptostringcelementtree

Django soaplib error


I'm trying to make a little "Hello World" webservice with Django following a few tutorials, but I'm hitting the same barrier over and over. I've defined a view.py and soaplib_handler.py:

view.py:

from soaplib_handler import DjangoSoapApp, soapmethod, soap_types

class HelloWorldService(DjangoSoapApp):

    __tns__ = 'http://saers.dk/soap/'

    @soapmethod(_returns=soap_types.Array(soap_types.String))
    def hello(self):
      return "Hello World"

soaplib_handler.py:

from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers import primitive as soap_types

from django.http import HttpResponse


class DjangoSoapApp(SimpleWSGISoapApp):

    def __call__(self, request):
        django_response = HttpResponse()
        def start_response(status, headers):
            status, reason = status.split(' ', 1)
            django_response.status_code = int(status)
            for header, value in headers:
                django_response[header] = value
        response = super(SimpleWSGISoapApp, self).__call__(request.META, start_response)
        django_response.content = "\n".join(response)

        return django_response

And it seems the "response = super...." line is giving me trouble. When I load up /hello_world/services.wsdl mapped in url.py I get:

AttributeError at /hello_world/service.wsdl 'module' object has no attribute 'tostring'

For the full error message, see here: http://saers.dk:8000/hello_world/service.wsdl

Do you have any suggestion as to why I get this error? And where is ElementTree defined?


Solution

  • @zdmytriv The line

    soap_app_response = super(BaseSOAPWebService, self).__call__(environ, start_response)
    

    should look like

    soap_app_response = super(DjangoSoapApp, self).__call__(environ, start_response)
    

    then your example works.