Fix bug NoneType has no encode method