fortiosapi
fortiosapi copied to clipboard
Format response cannot deal with non utf-8 characters
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
It was actually a quick fix for python 3. Do you have a suggestion for solving this ?
Will a configuration parameter for utf-8 solve your issue ?
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 .
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.