I\'m using Spyne (the example \"hello world\" code) to make a webservice that produces some json data and then I\'m trying to consume this data in javascript code i
You need add this as the first line of your service implementation:
ctx.transport.resp_headers['Access-Control-Allow-Origin'] = '*'
However, that can get very annoying very fast, so here's a way to properly implement it:
class CorsService(ServiceBase):
origin = '*'
def _on_method_return_object(ctx):
ctx.transport.resp_headers['Access-Control-Allow-Origin'] = \
ctx.descriptor.service_class.origin
CorsService.event_manager.add_listener('method_return_object',
_on_method_return_object)
So instead of using ServiceBase, you can now use CorsService as parent class to your services to get the CORS header automatically.
Also note that it's more secure to set the header value only to the domain that hosts the Spyne service instead of using a wildcard.