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!

Unleash Unified Security and Observability with Splunk Cloud Platform

     Now Available on Microsoft AzureOn Demand Now Step boldly into the AI revolution with enhanced security ...

Enterprise Security Content Update (ESCU) | New Releases

In March, the Splunk Threat Research Team had 2 releases of security content via the Enterprise Security ...

Join the Splunk Developer Program Hackathon: Splunk Build-a-thon!

The Splunk Developer Program is launching in beta, and we’re celebrating with an exciting hackathon! This is ...