AttributeError:’bytes’ object has no attribute ‘encode’

If you don’t know if a stringlike object is a Python 2 string (bytes) or Python 3 string (unicode). You could have a generic converter. Python3 shell: On Python 2 both these expressions evaluate to True: type(“hello”) == bytes and type(“hello”) == str. And type(u”hello”) == str evaluates to False, while type(u”hello”) == unicode is True. On Python 3 type(“hello”) == bytes is False, and type(“hello”) == str is True. And type(“hello”) … Read more