fix str.encode() under python 2.7