tomchristie/django-rest-framework — pull request #1549 by maxpeterson (2014-04-28 11:41:30+00:00)
Title: Ensure Token.generate_key returns a string.

From the discussion in https://github.com/tomchristie/django-rest-framework/pull/1382

In Python 3 `generate_key` returns a 'binary string' (e.g. ` b'2d341eea05bc8823d480423d772f246576401306'`) which results on `Token.key` being a binary string which I believe is causing `TypeError b'326f50029aac5deb1ccecd5aa5c66bc8816e43cf' is not JSON serializable` elsewhere in in drf when the token is created.

In Python 2 `binascii.hexlify(os.urandom(20))` > '3be95efcfdd73e1b6393ede2da2736f7088aca07'
In Python 3 `binascii.hexlify(os.urandom(20))` > b'2d341eea05bc8823d480423d772f246576401306'

( cc @xordoquy )