【问题标题】:Encoding Spyne SOAP XML response with Latin-1使用 Latin-1 编码 Spyne SOAP XML 响应
【发布时间】:2019-08-21 16:20:04
【问题描述】:

我最近设置了一个用于发送 XML 响应的 Spyne 应用程序。就目前而言,应用程序正在正确地发送响应——但是,它当前正在发送一个 UTF-8 编码的文档。我想将文档作为 Latin-1 (iso-8859-1) 编码发送。

我尝试使用“encoding=”参数,但除了更改标头之外,它似乎对响应没有任何影响。

以下是我的应用程序的代码:

import logging
from spyne import Application, rpc, ServiceBase, Integer, Unicode, AnyDict
from spyne import Iterable
from spyne.protocol.soap import Soap11
from spyne.protocol.xml import XmlDocument
from spyne.server.wsgi import WsgiApplication

class CoreService(ServiceBase):
    @rpc(Unicode, Unicode, Integer, Integer, _returns=AnyDict) #@rpc arguments corespond to the retrieve_score() arguments below
    def retreive_score(ctx):
        return score # This is a dictionary

application = Application([CoreService], 'spyne.iefp.soap',
                          in_protocol=Soap11(validator='lxml'),
                          out_protocol=XmlDocument(polymorphic=True, encoding='iso-8859-1'))

wsgi_application = WsgiApplication(application)

if __name__ == '__main__':
    import logging

    from wsgiref.simple_server import make_server

    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)

    logging.info("listening on port 8000")
    logging.info("wsdl is at: http://10.10.28.84:8000/?wsdl")

    server = make_server('0.0.0.0', 8000, wsgi_application)
    server.serve_forever()

【问题讨论】:

    标签: python soap spyne


    【解决方案1】:

    我修复了(并切换到 HttpRpc 进行输入,因为我手边没有 SOAP 客户端)并运行了您的代码。它对我有用。

    import logging
    from spyne import Application, rpc, ServiceBase, Integer, Unicode, AnyDict
    from spyne import Iterable
    from spyne.protocol.soap import Soap11
    from spyne.protocol.http import HttpRpc
    from spyne.protocol.xml import XmlDocument
    from spyne.server.wsgi import WsgiApplication
    
    
    class CoreService(ServiceBase):
    
        @rpc(Unicode, Unicode, Integer, Integer, _returns=AnyDict)
        def retrieve_score(ctx, s1, s2, i1, i2):
            return {'rain': u'yağmur'}  # This is a dictionary
    
    
    application = Application([CoreService], 'spyne.iefp.soap',
        in_protocol=HttpRpc(),
        out_protocol=XmlDocument(polymorphic=True, encoding='iso-8859-9'))
    
    wsgi_application = WsgiApplication(application)
    
    if __name__ == '__main__':
        import logging
    
        from wsgiref.simple_server import make_server
    
        logging.basicConfig(level=logging.DEBUG)
        logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
    
        logging.info("listening on port 8000")
        logging.info("wsdl is at: http://127.0.0.1:8000/?wsdl")
    
        server = make_server('0.0.0.0', 8000, wsgi_application)
        server.serve_forever()
    

    curl -s localhost:8000/retrieve_score | hexdump -C的摘录是:

    00000070  65 5f 73 63 6f 72 65 52  65 73 75 6c 74 3e 3c 72  |e_scoreResult><r|
    00000080  61 69 6e 3e 79 61 f0 6d  75 72 3c 2f 72 61 69 6e  |ain>ya.mur</rain|
    00000090  3e 3c 2f 6e 73 30 3a 72  65 74 72 69 65 76 65 5f  |></ns0:retrieve_|
    

    根据:https://en.wikipedia.org/wiki/ISO/IEC_8859-9,你有 0xF0 表示“ğ”,这是正确的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      • 2017-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多