0

I have written a SOAP web server with Django using this tutorial; I used the exact code disscussed in the tutorial and its linked tutorials.

This is my urls.py BTW:

from django.conf.urls import url
from django.contrib import admin
from views import hello_world_service

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^hello_world/', hello_world_service),
    url(r'^hello_world/service.wsdl', hello_world_service),
]

To call the method 'say_hello' I wrote multiple clients using different libraries:

Implementation with suds:

from suds.client import Client as SudsClient
url = 'http://127.0.0.1:5000/hello_world'
client = SudsClient(url=url, cache=None)

This is error traceback in the client side:

Traceback(most recent call last):
    File "client.py", line 14, in < module > client = SudsClient(url=url, cache=None)
    File "build/bdist.linux-x86_64/egg/suds/client.py", line 112, in __init__
    File "build/bdist.linux-x86_64/egg/suds/reader.py", line 152, in open
    File "build/bdist.linux-x86_64/egg/suds/wsdl.py", line 136, in __init__
    File "build/bdist.linux-x86_64/egg/suds/reader.py", line 79, in open
    File "build/bdist.linux-x86_64/egg/suds/reader.py", line 95, in download
    File "build/bdist.linux-x86_64/egg/suds/transport/https.py", line 60, in open
    File "build/bdist.linux-x86_64/egg/suds/transport/http.py", line 64, in open
suds.transport.TransportError: HTTP Error 405: Method Not Allowed

And this is what I get in the server console:

[24/Jul/2017 08:17:14] "GET /hello_world HTTP/1.1" 301 0
[24/Jul/2017 08:17:14] "GET /hello_world/ HTTP/1.1" 405 0

Another Implementation with suds:

I found it here.

from Tkinter import *
from suds.client import *
class SoapClass:
    def __init__(self, master):
        self.client = Client('http://127.0.0.1:5000/hello_world/', username='', password='', faults=False)
        Button(master, text='Call', command=self.request).pack()
    def request(self):
        methodName = 'getSmsDeliveryStatus'
        params = ['2656565656565']
        MethodToExecute = getattr(self.client.service, methodName)
        try:
            response = MethodToExecute(*params)
        except WebFault as e:
            response = e
        print(response)
root = Tk()
app = SoapClass(root)
root.mainloop()

This client returns the exact stacktrace in the client side as suds implementation does; but the server console shows a different error:

[24/Jul/2017 08:30:27] "GET /hello_world/ HTTP/1.1" 405 0

Implementation with requests:

import requests
target_url = "http://127.0.0.1:5000/hello_world/"
headers = {'Content-type': 'text/xml'}
data = {'id': '322424234234'}
print requests.post(target_url, data=data, headers=headers).text

In the client side, I get an HTML page which in general says CSRF verification failed. Request aborted. In the server side, I get:

Forbidden (CSRF cookie not set.): /hello_world/
[24/Jul/2017 08:44:51] "POST /hello_world/ HTTP/1.1" 403 2857

EDIT 1:

I tried disabling CSRF for this solution; I got this:

<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAP-ENV:Body><SOAP-ENV:Fault>
<faultcode>Server</faultcode>
<faultstring>'NoneType' object has no attribute 'startswith'</faultstring>
<detail>Traceback (most recent call last):
    File "/usr/lib/python2.7/dist-packages/soaplib/wsgi_soap.py", line 224, in __call__
        if methodname.startswith('"') and methodname.endswith('"'):
            AttributeError: 'NoneType' object has no attribute 'startswith'
</detail>
</SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

I think I forgot to fill some parameter in the request; could anyone please help me on that?

What is wrong with my clients getting connection and calling methods from server? Do I have to set some options in the server/client side?

Zeinab Abbasimazar
  • 9,835
  • 23
  • 82
  • 131
  • 1
    Try to disable CSRF, more details at: https://docs.djangoproject.com/en/1.11/ref/csrf/ – Guy S Jul 24 '17 at 09:08
  • @GuyS, I tried your solution; I edited my question based on it. Could you please review my edit under the section **Implementation with `requests`** and check if you can help me on that? – Zeinab Abbasimazar Jul 24 '17 at 11:02

0 Answers0