2013-03-13 69 views
3

如何在Django中使用基本身份驗證和Spyne?我試圖在下面,但它不工作。我可以很好地查看WSDL頁面文件,但每當我嘗試將SayHello作爲Web服務調用時,我都會收到403 FORBIDDEN響應。我相信403是CSRF相關的,但csrf_exempt不應該讓我知道嗎?順便說一下,logged_in_or_basicauth是從這個片段:http://djangosnippets.org/snippets/243/如何在Django中使用Spyne進行基本身份驗證?

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) 

回答

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(), 
)) 
+1

這是正確答案? – 2013-03-21 14:38:38

+0

它適合我! – esauro 2013-10-01 13:49:36

相關問題