In a Django project hosted on Google App Engine using the simplejwt library, I receive this error message as soon as I put the secret key into an environment variable and try to create a token at the jwt/create endpoint:
TypeError at /api/v1/auth/jwt/create/ Expected a string value
The key is stored in the apps yaml file as SECRET_KEY_ENV and loaded in Django's settings file like this:
SECRET_KEY = str(os.environ["SECRET_KEY_ENV"]),
The Database environment variables are loaded in exactly the same manner and everything is working fine.
The first time the key pops up in the error message is in this file:
/layers/google.python.pip/pip/lib/python3.9/site-packages/jwt/api_jwt.py, line 63, in encode
and in this form:
key : ('ai0eobey86soimfxb6ax4uqdmo49yiauxchgnspsh',)
from there he gets passed on to:
without being changed and the last file "utils.py"is the one raising the error message. I have tried changing the variable name, removing special characters from the key, moving the definition around inside the settings file, nothing works. As soon as I put it back into cleartext, it works fine but I can't keep doing that for obvious security reasons.
How can I fix this? Thanks and BR
Solving my own question here, it was the trailing comma where the key is declared that created this error. Removing the comma within the brackets fixed it.