fix encode bug, 'NoneType' object has no attribute 'encode'