我遇到了 Django 1.4 和 Soaplib 2.0 的问题。
当我从客户端发送带有一些大参数的请求时,Django 引发异常并发送此类电子邮件:“ [Django] ERROR (EXTERNAL IP): Internal Server Error: /uri/to/soap/service ”
Traceback (most recent call last):
File "/path/to/my/project/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 129, in get_response
raise ValueError("The view %s.%s didn't return an HttpResponse object." % (callback.__module__, view_name))
ValueError: The view myproject/library.soap.wsgi.view didn't return an HttpResponse object.
我在服务器端使用http://soaplib.github.io/soaplib/2_0/pages/helloworld.html#declaring-a-soaplib-service提供的普通 @soap 装饰器。
所以,它在服务器配置上看起来像这样:
在urls.py里面:
from myproject.server.webservice import WebService
application_view = Application([WebService], 'ws', name='ws').as_django_view()
urlpatterns = patterns(
url(r'^soap/.*', csrf_exempt( application_view )),
)
在myproject/server/webservice.py里面:
from soaplib.core.service import DefinitionBase
class WebService(DefinitionBase):
'''
The actual webservice class.
This defines methods exposed to clients.
'''
def __init__(self, environ):
'''
This saves a reference to the request environment on the current instance
'''
self.environ = environ
super(WebService, self).__init__(environ)
@soap(Array(Array(String)), _returns=Integer)
def my_method(self, params):
return self.process(params)
def process(self, params):
#DO SOMETHING HERE
在客户端:
#cfg is my configuration file
#params is a dictionary
client = SoapClient(
location = cfg.location,
action = cfg.action, # SOAPAction
namespace = cfg.namespace, #"http://example.com/sample.wsdl",
soap_ns= cfg.soap_ns,
trace = cfg.trace,
ns = cfg.ns)
response = client.my_method(params=params)
我试图从我的客户那里发送非常大的字典,但它不起作用。
我怀疑 Django 设置超时并在此过程中关闭我的连接。无论如何增加超时还是由其他原因引起的问题?
顺便说一句,我只使用 Django。我没有配置任何 Apache 或 Nginx。