首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spyne in_protocol Soap11和http标头

Spyne in_protocol Soap11和http标头
EN

Stack Overflow用户
提问于 2016-03-15 17:20:41
回答 1查看 1.2K关注 0票数 0

我不能在Spyne中处理http和https头。我有NginX + Twisted + Spyne,它工作得很好,但我需要在Spyne中获得过滤功能的userId。也许我应该在别的地方挖掘?

代码是:客户端:

代码语言:javascript
复制
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

服务器:

代码语言:javascript
复制
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())

错误:

代码语言:javascript
复制
ERROR:spyne.application.server:'NoneType' object has no attribute 'ee'

先谢谢你,尤里

EN

回答 1

Stack Overflow用户

发布于 2016-03-16 20:26:50

当您的in_protocol是SOAP时,ctx.in_headers用于soap标头。如果要检查HTTP标头,实际上需要查看传输标头。

由于每种传输方式都有自己的处理方式,因此这些方式大多是特定于传输方式的。对于Twisted HTTP,您需要从Twisted的HTTP包中获取请求对象。

您可以使用ctx.transport.req来获取该对象。

至于从中提取头部,您需要参考Twisted文档。

为了您的方便,下面是相关页面:

https://twistedmatrix.com/documents/current/api/twisted.web.http.Request.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36007056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档