Ok pytest -v -m user_management instead Nok status profile check User Managment

hi to everyone,

i don’t understand why pytest -v -m user_management is passed, and relative status profile row “User Managment” is on error.

this is the trouble :slight_smile:

127.0.0.1 - - [13/Feb/2022 13:45:20] "POST /api/v1/user/register HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/flavio/Documents/Develop_MongoDB/mflix/api/user.py", line 116, in register
    jwt = create_access_token(user.to_json())
  File "/opt/conda/envs/mflix/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 "/opt/conda/envs/mflix/lib/python3.9/site-packages/flask_jwt_extended/jwt_manager.py", line 393, in _create_access_token
    access_token = encode_access_token(
  File "/opt/conda/envs/mflix/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 "/opt/conda/envs/mflix/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 have also tried to fill sign-up and sign-in procedure on website, and go on error with the same stack error, but entry is inserted on DB i have checked it.
Seemed that the trouble is on website more than procedure.
please can you help ?
i wish to pass further

thank you

Hi @flavio_joshua,

Welcome to the MongoDB community forums! :leaves:

I don’t understand why pytest -v -m user_management is passed, and relative status profile row “User Managment” is on error.

All test cases passed and none got skipped/failed? When you check the status for User Management, what is the error message that you see there?

AttributeError: 'str' object has no attribute 'decode'

From the error statements you posted, it seems there is some error in the implementations of the functions. Hence, I’ll recommend re-checking your implementations. Since the error statements also mention jwt, maybe start by rechecking the login_user function. Possibly you are creating something as a string that should not be done. Remember to use the $set operator for jwt variable since we are updating the JWT corresponding with that user’s email in the sessions collection.

This also suggests that there may be some issue with the add_user function as well. I would recommend you to make sure to read the comments to better understand the task.

If these don’t help, try posting your implementations so that someone from our wonderful community can have a look to point you in the right direction and if you already solved this, feel free to post what worked for you!:smile:

Feel free to reach out for anything else as well.

Regards,
Satyam