获取"方法不允许"调用Django SOAP Web服务器时出错

时间:2017-07-24 08:49:00

标签: python django web-services soap soapserver

我使用this tutorial编写了一个带有Django的SOAP Web服务器;我使用了教程及其链接教程中讨论的确切代码。

这是我的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),
]

调用方法' say_hello'我使用不同的库编写了多个客户端:

使用suds实施

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

这是客户端的错误回溯:

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

这就是我在服务器控制台中获得的内容:

[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

suds的另一项实施:

我发现它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()

此客户端在suds实现时返回客户端中的确切堆栈跟踪;但服务器控制台显示不同的错误:

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

使用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

在客户端,我得到一个HTML页面,一般说 CSRF验证失败。请求已中止。在服务器端,我得到:

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

编辑1:

我尝试为此解决方案禁用CSRF;我明白了:

<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>

我想我忘了在请求中填写一些参数;有人可以帮我吗?

我的客户从服务器获取连接和调用方法有什么问题?我是否必须在服务器/客户端设置一些选项?

0 个答案:

没有答案