Fixes byte/string encoding when unicode used

This is a backport from an issue reported in 2.8.x that exists in 2.7.x
also. See #102.