Charlie
Charlie

Reputation: 151

How can I use Basic Authentication with Spyne in Django?

How can I use Basic Authentication with Spyne in Django? I attempted the below but it isn't working. I can view the WSDL page file fine, but I'm getting a 403 FORBIDDEN response whenever I actually try to call SayHello as a web service. I believe the 403 is CSRF related, but shouldn't the csrf_exempt get me around that? BTW, logged_in_or_basicauth is from this snippet: 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)

Upvotes: 3

Views: 1883

Answers (1)

s-block
s-block

Reputation: 318

You could try

foo_view = csrf_exempt(foo_view)

below the definition of foo_view. Then you don't need the crsf_exempt around the other

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

Upvotes: 6

Related Questions