From 295be53c4837d0c3c23fc1eeb05ff707adc43803 Mon Sep 17 00:00:00 2001 From: AnuragBalhra Date: Sat, 15 Apr 2023 18:31:02 +0100 Subject: [PATCH 1/2] Updated PyJWT version to 2.6.0 As mentioned in the issue here: https://github.com/mattupstate/flask-jwt/issues/147 The PyJWT dependency used in current version of FlaskJWT seems to be using an older version of PyJWT that is causing following error: ImportError: cannot import name 'Mapping' from 'collections' Upgraded the PyJWT version to use version 2.6.0 to resolve this issue --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 953d69b..1f18ef5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ Flask>=0.9 -PyJWT>=1.4.0,<1.5.0 +PyJWT>=2.6.0 From aaaaa24301098c7cdb4e791e8e09750aa1da7d3e Mon Sep 17 00:00:00 2001 From: AnuragBalhra Date: Sat, 22 Apr 2023 14:58:35 +0100 Subject: [PATCH 2/2] Added try catch to handle Attribute Error in Python 3 Python 3 doesn't support str.decode method. So, trying to decode access_token in python 3 raises following error: AttributeError: 'str' object has no attribute 'decode' Added try except block to prevent that. --- flask_jwt/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flask_jwt/__init__.py b/flask_jwt/__init__.py index f864b78..754568e 100644 --- a/flask_jwt/__init__.py +++ b/flask_jwt/__init__.py @@ -129,7 +129,12 @@ def _default_auth_request_handler(): def _default_auth_response_handler(access_token, identity): - return jsonify({'access_token': access_token.decode('utf-8')}) + try: + token = access_token.decode('utf-8') + except AttributeError: + # There is no str.decode method in Python 3, so we can use the access token directly + token = access_token + return jsonify({'access_token': token}) def _default_jwt_error_handler(error):