cancel
Showing results for 
Search instead for 
Did you mean: 

Python Course test three Attribute Error

RSam3
Node Link

I haven't seen anyone else posting with this issue, so its probably something I did on accident that broke the test.

Nonetheless, just in case someone else runs into this issue, I am posting about it here. I have also provided feedback in the course itself with the same thing.

The issue:
Test 03 of the Python Course gives FAILED tests/03_registering_a_user__test.py::test_register_user - AttributeError: 'str' object has no attribute 'decode'

The cause:
In auth.py, the return statement in the _generate_token function has ".decode('ascii')" at the end.

I fixed this by removing that part of the return statement, as it seems to me that the next function down already decodes the token (being literally named decode_token), however I do not know if this will break anything further down the line.

I would like to know if this is intentionally part of the return statement, and if its supposed to give  the  attribute error. Thank you.

2 REPLIES 2

PhilR
Node

I encountered the same error.

dagg
Node

I encountered the same issue, and also have issues with 'register' and 'sign in' when running the app in my browser.

Changed to JWT_SECRET_KEY in ./routes/auth.py

def register():
    ...
    dao = AuthDAO(current_app.driver, current_app.config.get("JWT_SECRET_KEY"))
    ...

def login():
    ...
    dao = AuthDAO(current_app.driver, current_app.config.get("JWT_SECRET_KEY"))
    ...

Modified _generate_token function with a try except block

 

def _generate_token(self, payload)
    ...
    encoded = jwt.encode(payload, self.jwt_secret, algorithm="HS256")
    try:
        return encoded.decode("ascii")
    except AttributeError:
        return encoded