Open yuhr123 opened 6 years ago
Please consider this
Hi @yuhr123! Thank you for your contribution!
Could you please explain how to reproduce the error you are trying to fix? What version of Python does it affect -- 2 or 3?
I don't think that this solution is appropriate as it breaks a valid use case on Python 3 when flask_secret_key
is str
with following error:
> key = key + b' '*32 # Make sure the key is at least 32 bytes long
E TypeError: can only concatenate str (not "bytes") to str
Maybe you wanted to do the opposite?
if sys.version_info[0] < 3:
key = flask_secret_key
else:
key = flask_secret_key.encode()
So don't encode
on python2 as str
is already a byte string, but do encode
on python3 to get bytes
.
can we push this please having difficulty with docker images that rely on this this change enables it to work on py3
I use urandom() for a secret key generation. The key is always in bytes. And it doesn't matter which version of python is in use.
I guess something like this:
if isinstance(key, bytes):
key = flask_secret_key
else:
key = flask_secret_key.encode()
PS Sorry, I'm new here. I don't know how to work correctly with github system.
The key field already be decode in Python 3. So I add a condition statement to check version of python to fix this error.