Make string encoding be compatible with 2.7 and 3.