Ticket: User Management Test Pass / Status Error

Hi Everyone,

I came across the situation where the unit tests are all passed but the status page returns errors.
About the .ini file, I tried both the one shown below and the version without the string “sample_mflix” in the URI (which is the original one I copied from Atlas)

Notice that I didn’t change the cluster/user name I created with m001.

The screenshots are as follows.

Anyone can help with this one? Much appreciated!

up until this lab, you have dealt with "read"ing data. now you “write” data. did you give your user “write access”?

also, open developer tools, switch to the console tab, and see what error you are getting, along with any error you might be getting from your server app console.

Hi Yilmaz! Thank you for paying attention.

I checked my user setting and it’s “read and write to any database” privilege.

The terminal came back with errors like this:

File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/app.py”, line 1997, in call
return self.wsgi_app(environ, start_response)
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/app.py”, line 1985, in wsgi_app
response = self.handle_exception(e)
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask_cors/extension.py”, line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/app.py”, line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/_compat.py”, line 33, in reraise
raise value
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/app.py”, line 1982, in wsgi_app
response = self.full_dispatch_request()
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/app.py”, line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask_cors/extension.py”, line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/app.py”, line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/_compat.py”, line 33, in reraise
raise value
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/app.py”, line 1612, in full_dispatch_request
rv = self.dispatch_request()
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask/app.py”, line 1598, in dispatch_request
return self.view_functionsrule.endpoint
File “/Users/joeyto/Downloads/mflix-python/mflix/api/user.py”, line 116, in register
jwt = create_access_token(user.to_json())
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask_jwt_extended/utils.py”, line 112, in create_access_token
return jwt_manager._create_access_token(identity, fresh, expires_delta)
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask_jwt_extended/jwt_manager.py”, line 393, in _create_access_token
access_token = encode_access_token(
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask_jwt_extended/tokens.py”, line 73, in encode_access_token
return _encode_jwt(token_data, expires_delta, secret, algorithm)
File “/Users/joeyto/opt/anaconda3/lib/python3.9/site-packages/flask_jwt_extended/tokens.py”, line 29, in _encode_jwt
encoded_token = jwt.encode(token_data, secret, algorithm).decode(‘utf-8’)
AttributeError: ‘str’ object has no attribute ‘decode’

I googled it a bit - should I go to the tokens.py file and drop the decode part?

Thanks again!

Hi Yilmaz, I actually went ahead and drop the decode part! And it worked!

For anyone who has come across the same problem, line 29 of the tokens.py is now:
encoded_token = jwt.encode(token_data, secret, algorithm)

Thank you forum and hope everyone enjoys the beautiful debug process! :laughing:

although it might help, you are changing a library code, and you should discourage yourself by doing that as much as possible.

this might just be a bug in a new version of the library, or library is perfect and the application we write uses some functions that are incompatible between versions. what you have seemingly fixed might break somewhere else.

I am also amazed how pip’s use of cached packages when installing can result in many problems, or conda giving me headaches with pytest, tying to it some missing packages it should not. you may also consider adding --no-cache-dir to pip install command.

But I would suggest another way: Install an older virtual python environment. Because the app would perfectly run with all library versions from “requirements.txt”. The app is about 4 years old, and it is python 3.6 or 3.7 at the time this app was made.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.