3

如何在 Django 中使用 Spyne 的基本身份验证?我尝试了以下方法,但它不起作用。我可以很好地查看 WSDL 页面文件,但是每当我实际尝试将 SayHello 作为 Web 服务调用时,我都会收到 403 FORBIDDEN 响应。我相信 403 与 CSRF 相关,但 csrf_exempt 不应该让我解决这个问题吗?顺便说一句,logged_in_or_basicauth 来自这个片段:http ://djangosnippets.org/snippets/243/ 。

class CapsWebService(ServiceBase):
    @rpc(String, Integer, _returns=Iterable(String))
    def SayHello(ctx, name, times):
        for i in xrange(times):
            yield 'Hello, %s' % name

caps_web_service = csrf_exempt(DjangoApplication(Application(
    [CapsWebService], 'solutions.sfcs', in_protocol=Soap11(), out_protocol=Soap11(), interface=Wsdl11(),
)))

@logged_in_or_basicauth()
def foo_view(request):
    logger.debug('views.foo_view()')
    return caps_web_service(request)
4

1 回答 1

6

你可以试试

foo_view = csrf_exempt(foo_view)

在 foo_view 的定义之下。那么你就不需要 crsf_exempt 了

caps_web_service = DjangoApplication(Application(
    [CapsWebService], 'solutions.sfcs', in_protocol=Soap11(), out_protocol=Soap11(),         interface=Wsdl11(),
))
于 2013-03-14T12:36:13.750 回答