django-aesfield
django-aesfield copied to clipboard
Error when generating new key
Using python 3.4 and django 1.11 I get the following when I try to generate a key:
File ".../aesfield/management/commands/generate_aes_keys.py", line 16, in generate_key
return os.urandom(byte_length).encode('hex')
AttributeError: 'bytes' object has no attribute 'encode'
We're officially only testing against Python 2.7, 3.5 and 3.6. Unfortunately, I don't have time to also maintain Python 3.4, so if you need support for it please feel free to submit a pull request and I'm very happy to merge it.
@EnTeQuAk Well, I'm getting the same error with Python 3.6.2.
Steps to reproduce:
- start a new Django project in Python 3.6.2 virtualenv
- install django-aesfield
- add to settings:
AES_KEYS = {
'default': os.path.join(os.path.dirname(__file__), 'sample.key')
}
-
python manage.py generate_aes_keys
@EnTeQuAk The management command really doesn't work in Python 3, because os.urandom produces bytes object which doesn't have decode
method.
One possible solution would be something like binascii.hexlify(os.urandom(byte_length)).decode()
. It gives unicode string in Python 2 and string in Python 3.
Ugh, indeed. I'll have a look at this shortly.