0

I'm trying to print a certain key from a loop and getting some issues. Tried to search other responses but still having issues.

import json
from azure.graphrbac import GraphRbacManagementClient
from azure.graphrbac.models import UserCreateParameters, PasswordProfile
from azure.common.credentials import UserPassCredentials

admin_user_name = ''
admin_password = ''
# e.g. yourcompany.onmicrosoft.com
tenant_id = ""

credentials = UserPassCredentials(
            admin_user_name,
            admin_password,
            resource="https://graph.windows.net"
    )

graphrbac_client = GraphRbacManagementClient(
    credentials,
    tenant_id
)

users = graphrbac_client.users.list();
for user in users:
    print [user['mail_nickname']]

the key I only want to extract is called mail_nickname

I get this error

TypeError: 'User' object has no attribute '__getitem__'

I only do print(user) that works fine but loads data I don't need.

Any help would be appreciated. Thanks

1
  • 1
    Isn't it just an attribute of user, e.g. user.mail_nickname? Commented Aug 10, 2018 at 5:02

1 Answer 1

1

Try to use user.mail_nickname rather than user['mail_nickname']. The error occurs when a object doesn't support get operator using brackets like user['id'].

Or try to print(dir(user)). It would help you to check attributes you can use.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.