Splunk Dev

python sdk raises keyerror while listing roles of user

sathiyamoorthy
Explorer

Following this example to list user and display properties from here: http://dev.splunk.com/view/python-sdk/SP-CAAAEJ6#listusers ends up in the following error:

Users:
Administrator (admin)
Traceback (most recent call last):
  File "splunk.py", line 16, in <module>
    for role in user.role_entities:
  File "/usr/lib/python2.6/site-packages/splunklib/client.py", line 3054, in role_entities
    return [self.service.roles[name] for name in self.content.roles]
  File "/usr/lib/python2.6/site-packages/splunklib/client.py", line 3195, in __getitem__
    return Collection.__getitem__(self, key.lower())
  File "/usr/lib/python2.6/site-packages/splunklib/client.py", line 1163, in __getitem__
    raise KeyError(key)
KeyError: 'admin'

shell returned 1

Copied and used the code snippet from above link, and logged in as admin using following

service = splunkclient.connect(host='sh1.hostname',
                     port=8089,
                     username='admin',
                     password='adminpassword')

# Get the collection of users, sorted by realname
kwargs = {"sort_key":"realname", "sort_dir":"desc"}
users = service.users.list(count=-1,**kwargs)

# Print the users' real names, usernames, and roles
print "Users:"
for user in users:
    print "%s (%s)" % (user.realname, user.name)
    for role in user.role_entities:
        print " - ", role.name

Using splunk 6, python sdk 1.0.0. Can someone please help to overcome this issue?

Tags (4)
1 Solution

gblock_splunk
Splunk Employee
Splunk Employee

Hi @sathiamoorthy

Sorry you are having problems. we've ran this code with our latest SDK on OSX 10 and did not hit any issues. Can you try this out with our latest SDK 1.2.3 and let us know if you still see it?

Thanks!
Glenn

View solution in original post

gblock_splunk
Splunk Employee
Splunk Employee

Hi @sathiamoorthy

Sorry you are having problems. we've ran this code with our latest SDK on OSX 10 and did not hit any issues. Can you try this out with our latest SDK 1.2.3 and let us know if you still see it?

Thanks!
Glenn

sathiyamoorthy
Explorer

Yes 1.2.3 doesn't have this issue, thanks.

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...