catch UnicodeDecodeErrors from simplejson.
This commit is contained in:
parent
28da601ad3
commit
6c7e722390
2 changed files with 9 additions and 1 deletions
|
@ -63,6 +63,9 @@ def parseConfigFile(configFile):
|
||||||
'verbose': False,
|
'verbose': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if not os.path.isfile(configFile):
|
||||||
|
return configs
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(configFile) as fh:
|
with open(configFile) as fh:
|
||||||
for line in fh:
|
for line in fh:
|
||||||
|
|
|
@ -25,7 +25,12 @@ class CustomEncoder(json.JSONEncoder):
|
||||||
if isinstance(obj, bytes):
|
if isinstance(obj, bytes):
|
||||||
obj = bytes.decode(obj)
|
obj = bytes.decode(obj)
|
||||||
return json.dumps(obj)
|
return json.dumps(obj)
|
||||||
return super(CustomEncoder, self).default(obj)
|
try:
|
||||||
|
encoded = super(CustomEncoder, self).default(obj)
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
obj = obj.decode('utf-8', 'ignore')
|
||||||
|
encoded = super(CustomEncoder, self).default(obj)
|
||||||
|
return encoded
|
||||||
|
|
||||||
|
|
||||||
class JsonFormatter(logging.Formatter):
|
class JsonFormatter(logging.Formatter):
|
||||||
|
|
Loading…
Reference in a new issue