Added detection of unicode for python2 to prevent double encoding, may break python3