fortinet-solutions-cse / fortiosapi

Python library aimed to be used by configuration management system using Fortigate/Fortios devices (REST API)
https://fndn.fortinet.com
Apache License 2.0
115 stars 41 forks source link

Format response cannot deal with non utf-8 characters #21

Open jimmelville opened 6 years ago

jimmelville commented 6 years ago

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
thomnico commented 5 years ago

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

thomnico commented 5 years ago

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

jimmelville commented 5 years ago

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" notifications@github.com 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 .

tchession commented 5 years ago

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.