'NoneType' object has no attribute 'get'

Hello Everyone, I am getting an issue with testing my user management assignment.

This is my error message, which does not seem to refer to anything that i worked on or changed. Everything else seems to be working fine.

client = <FlaskClient <Flask ‘mflix.factory’>>

  • @pytest.mark.user_management*
  • def test_login(client):*
  •    result = login_user(test_user.get('email'), test_user.get('jwt'))*
  •    assert result == {'success': True}*
  •    session_result = get_user_session(test_user.get('email'))*

> assert session_result.get(‘user_id’) == test_user.get(‘email’)
E AttributeError: ‘NoneType’ object has no attribute ‘get’

What do they mean by nonetype object not having an attribute ‘get’? Thanks in advance for your help!

This means that object for which we are calling get function is of NoneType. In this case, it seems like in the below line of code, test_user seems to be null or maybe the code you have written for login_user function needs to be looked at.

Please share the code changes you have done and also make sure to share error with the screenshot after you run test.


Hello Kanika, This is my login_user function:

def login_user(email, jwt):

  • try:*
  •    # TODO: User Management*
  •    # Use an UPSERT statement to update the "jwt" field in the document,*
  •    # matching the "user_id" field with the email passed to this function.*
  •    db.sessions.update_one(*
  •        { "user_id": email },*
  •        { "$set": { "jwt": jwt } }*
  •    )*
  •    return {"success": True}*
  • except Exception as e:*
  •    return {"error": e}*


Hi @Raghuram_Vadali_03611,

You need to set upsert to true in your query. You can refer to the API on how to use it in the code.


1 Like

It works now! Thank you for your help Kanika!