Because of how python3 handles byte>str conversion, the passcode generation function produces a mangled result in python3. The reason the unit tests still pass in python3 is because the tests also use the same function and thus the server and the tests are both sending and expecting the same mangled passcode.
The fix is to not use six.text_type, as it does the wrong thing, and instead use .decode('utf-8') which produces the correct result in both python2 and python3.
Because of how python3 handles byte>str conversion, the passcode generation function produces a mangled result in python3. The reason the unit tests still pass in python3 is because the tests also use the same function and thus the server and the tests are both sending and expecting the same mangled passcode.
The fix is to not use six.text_type, as it does the wrong thing, and instead use .decode('utf-8') which produces the correct result in both python2 and python3.
Example of why and how this happens:
Python2:
>>> passcode = b'123456' type(passcode) text_type( passcode) ) decode( 'utf-8' ) decode( 'utf-8' ))
>>> print passcode
123456
>>> type(passcode)
<type 'str'>
>>> import six
>>> six.text_
u'123456'
>>> type(six.
<type 'unicode'>
>>> otherstring = "openstack"
>>> otherstring + passcode
'openstack123456'
>>> passcode.
u'123456'
>>> type(passcode.
<type 'unicode'>
Python3:
>>> passcode = b'123456' type(passcode) text_type( passcode) ) 123456' " decode( 'utf-8' ) decode( 'utf-8' ))
>>> print(passcode)
b'123456'
>>> type(passcode)
<class 'bytes'>
>>> import six
>>> six.text_
"b'123456'"
>>> type(six.
<class 'str'>
>>> otherstring = "openstack"
>>> otherstring + passcode
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Can't convert 'bytes' object to str implicitly
>>> otherstring + str(passcode)
"openstackb'
>>> passcode.
'123456'
>>> type(passcode.
<class 'str'>