use codecs.encode for python2.6 compatibility