0

I recently set up a Spyne application for sending an XML response. As it stands now, the application is correctly sending the response -- however, it is currently sending a UTF-8 encoded document. I would like to instead send the document as Latin-1 (iso-8859-1) encoded.

I've tried to use the "encoding=" argument, but it seems to have no effect on the response beyond changing the header.

Below is the code for my application:

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()
Andrew Bell
  • 49
  • 1
  • 4

1 Answers1

0

I fixed (and switched to HttpRpc for input as I didn't have a SOAP client handy) and ran your code. It works for me.

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()

The excerpt from curl -s localhost:8000/retrieve_score | hexdump -C is:

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_|

Where you have 0xF0 for 'ğ', which is correct, according to: https://en.wikipedia.org/wiki/ISO/IEC_8859-9

Burak Arslan
  • 7,671
  • 2
  • 15
  • 24