fix #17 by removing non-utf8 characters

This commit is contained in:
Alan Hamlett 2013-11-21 01:09:37 -08:00
parent 03ec38bb67
commit 049bc57019
2 changed files with 9 additions and 1 deletions

View File

@ -63,6 +63,9 @@ def parseConfigFile(configFile):
'verbose': False,
}
if not os.path.isfile(configFile):
return configs
try:
with open(configFile) as fh:
for line in fh:

View File

@ -25,7 +25,12 @@ class CustomEncoder(json.JSONEncoder):
if isinstance(obj, bytes):
obj = bytes.decode(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):