use encodebytes instead of encodestring (#2483)