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!

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...