hl7apy icon indicating copy to clipboard operation
hl7apy copied to clipboard

Encoding of mllp server is hard-coded to 'utf-8'

Open LuukOost opened this issue 7 years ago • 1 comments

The mllp server encoding is hard-coded to 'utf-8'. This can result in errors if decoding of stream fails due to other encoding.

Solution: change __init__ of MLLPServer:

    def __init__(self, host, port, handlers, timeout=10, char_encoding='utf-8'):
        self.host = host
        self.port = port
        self.handlers = handlers
        self.timeout = timeout
        self.char_encoding = char_encoding
        TCPServer.__init__(self, (host, port), _MLLPRequestHandler)

remove hardcoded encoding in _MLLPRequestHandler and add to setup:

        self.encoding = self.server.char_encoding

LuukOost avatar Jul 11 '17 13:07 LuukOost

I don't think this is an issue any more. The encoding can be customized like so:

from hl7apy.mllp import MLLPRequestHandler, MLLPServer

class CustomMLLPRequestHandler(MLLPRequestHandler):
    encoding = "latin1"

MLLPServer(..., request_handler_class=CustomMLLPRequestHandler)

gediminasz avatar Oct 11 '21 10:10 gediminasz