fortiosapi icon indicating copy to clipboard operation
fortiosapi copied to clipboard

Format response cannot deal with non utf-8 characters

Open jimmelville opened this issue 7 years ago • 4 comments

The fortigate supports non utf-8 characters, suggestion to replace these when formatting response:

def formatresponse(self, res, vdom=None):
        LOG.debug("formating response")
        self.logging(res)
        # Generic way to format the return from FortiAPI
        # If vdom is global the resp is a dict of resp (even 1)
        # 1 per vdom we check only the first one here (might need a more
        # complex check)
        if vdom == "global":
            resp = json.loads(res.content.decode('utf-8', errors='replace'))[0]
            resp['vdom'] = "global"
        else:
            LOG.debug("content res: %s", res.content)
            resp = json.loads(res.content.decode('utf-8', errors='replace'))
        return resp

jimmelville avatar Jul 20 '18 09:07 jimmelville

It was actually a quick fix for python 3. Do you have a suggestion for solving this ?

thomnico avatar Nov 11 '18 18:11 thomnico

Will a configuration parameter for utf-8 solve your issue ?

thomnico avatar Dec 20 '18 11:12 thomnico

I've moved on from this project. I believe a workaround for the issue I faced was to re-add the object. There is a firmware fix that may have resolved this. We were using 5.2.3

On 20 Dec 2018 11:06, "Nicolas Thomas" [email protected] wrote:

Will a configuration parameter for utf-8 solve your issue ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fortinet-solutions-cse/fortiosapi/issues/21#issuecomment-448959193, or mute the thread https://github.com/notifications/unsubscribe-auth/AG7kY22C3yLiFDLn7f7SHLPDU4j1DaFSks5u629BgaJpZM4VXvPx .

jimmelville avatar Dec 20 '18 11:12 jimmelville

Hello,

I have run into this issue on two different units running 5.6.7. I've created a few dozen objects using this library and now get the UTF-8 decoding errors when getting them back. I don't believe I've used any characters outside of Unicode. Adding errors='replace' to the UTF-8 decode does resolve the issue.

tchession avatar Mar 26 '19 13:03 tchession