我无法在 Spyne 中处理 http 和 https 标头。我有 NginX + Twisted + Spyne,它运行良好,但我需要在 Spyne 中获取 userId 以实现过滤功能。也许我应该在其他地方挖掘?
代码是:客户端:
url_service = 'http://localhost:8000/?wsdl'
client = suds.client.Client(url_service)
client.set_options(headers={'ee': 'we'}, username = 'login')
w = client.service.get_head('neo')
print w
服务器:
import logging
import random
import sys
import base64
from spyne.application import Application
from spyne.decorator import rpc
from spyne.error import ResourceNotFoundError
from spyne.model.complex import ComplexModel
from spyne.model.fault import Fault
from spyne.model.primitive import Mandatory
from spyne.model.primitive import String
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from spyne.service import ServiceBase
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.wsgi import WSGIResource
from twisted.python import log
class RequestHeader(ComplexModel):
__tns__ = 'spyne.examples.authentication'
username = unicode()
ee = unicode()
class UserService(ServiceBase):
__tns__ = 'spyne.examples.authentication'
__in_header__ = RequestHeader
@rpc(Mandatory.String, _returns=String)
def get_head(ctx, user_name):
print '*'*20
print ctx.in_header_doc
print ctx.in_body_doc
print ctx.in_header.ee
retval = "Where's the header"
return retval
def _on_method_call(ctx):
return
UserService.event_manager.add_listener('method_call', _on_method_call)
HOST = '127.0.0.1'
PORT = 8000
if __name__=='__main__':
from spyne.util.wsgi_wrapper import run_twisted
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
logging.getLogger('twisted').setLevel(logging.DEBUG)
application = Application([UserService],
tns='spyne.examples.authentication',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11()
)
wsgi_app = WsgiApplication(application)
resource = WSGIResource(reactor, reactor, wsgi_app)
site = Site(resource)
reactor.listenTCP(PORT, site, interface=HOST)
logging.info("listening to http://127.0.0.1:8000")
logging.info("wsdl is at: http://localhost:8000/?wsdl")
sys.exit(reactor.run())
错误:
ERROR:spyne.application.server:'NoneType' object has no attribute 'ee'
提前感谢,尤里