flask-api-tutorial icon indicating copy to clipboard operation
flask-api-tutorial copied to clipboard

PyJWT encode return type has changed

Open bytefoundry-git opened this issue 4 years ago • 1 comments

As of version 2.0, the return type for jwt.encode is string instead of byte string, causing encode and decode tests to fail.

bytefoundry-git avatar Mar 31 '21 05:03 bytefoundry-git

After reading this I've added these 3 lines to the end of encode_access_token in models.user.py

    token = jwt.encode(payload, key, algorithm="HS256")
    if isinstance(token, str):
        token = token.encode("UTF-8")

which resolved this issue for me. Perhaps it has introduced new issues, hope not!

jaytaytay avatar Feb 14 '22 00:02 jaytaytay