factory.py: fix logging UnicodeDecodeError