Using ListUsers—Help | ArcGIS Desktop as my reference I'm trying to get a list of users connected to an eGDB that I can iterate through.
The online help page suggests:
# Set the admistrative workspace connection
arcpy.env.workspace = "Database Connections/tenone@sde.sde"
# Create a list of users
'''
NOTE: When the arcpy.env.workspace environment is set, a workspace
does not need to be provided to the function.
'''
users = arcpy.ListUsers()
However, my attempt errors out:
>>> arcpy.env.workspace = r'I:\PathTo\SdeUserConnection\sde@My.sde'
>>> users = arcpy.ListUsers()
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: ListUsers() takes exactly 1 argument (0 given)
If I specify the workspace and output it to a variable name, I get a list of tuples, which is cool, but then I have to step through it and tease out what I want:
ws = arcpy.env.workspace #set in line 1 above...
users = arcpy.ListUsers(ws)
>>> users
[user(ClientName=u'ad-trasmussen:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 8, 1, 14), ID=388635, IsDirectConnection=True, Name=u'"SLCOUNTY\\TARASMUSSEN"'), user(ClientName=u'AD-TBAIN-10:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 8, 6, 13), ID=388636, IsDirectConnection=True, Name=u'"SLCOUNTY\\TBAIN"'), user(ClientName=u'ad-trasmussen:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 8, 11, 12), ID=388637, IsDirectConnection=True, Name=u'"SLCOUNTY\\TARASMUSSEN"'), user(ClientName=u'AD-TBAIN-10:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 8, 11, 32), ID=388638, IsDirectConnection=True, Name=u'"SLCOUNTY\\TBAIN"'), user(ClientName=u'AD-BLECHEMINANT:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 10, 39, 34, 1), ID=388640, IsDirectConnection=True, Name=u'"SLCOUNTY\\BLECHEMINANT"'), user(ClientName=u'is-jborgione-10:10.5.1.7333', ConnectionTime=datetime.datetime(2018, 6, 22, 11, 30, 20), ID=388641, IsDirectConnection=True, Name=u'SDE')]
for i in range(len(users)):
... print users[i][4]
#prints the user name
But I'd rather not do that if I don't have to: I'd much rather use the list object/methods to step through so I can get user.name or user.ID
What's the secret to get arcpy.ListUsers() to work as advertised?
ListUsers—ArcPy Functions | ArcGIS Desktop
returns a tuple as advertised
The second example uses the object method, and it assumes that you are the administrator for the connection though... don't know if that is the issue but look at it and give it a whirl
#......
# import stuff clipped
users = arcpy.ListUsers()
# Create a list of SDE ID's.
# Use a list comprehension to get the ID values in a new list.
id_users = [user.ID for user in users]
That's what I did Dan: my line 2 is the same as your line 4. It errors out complaining that I didn't provide it with the args it's looking for.[My line 6: TypeError: ListUsers() takes exactly 1 argument (0 given)]
I don't get what's up with that....
As suggested from the code samples, it seems to be an admin permissions thing... one example uses () and the other doesn't depending on the admin level... I don't work in that environment, so I thought you might know... unless it is a python ArcMap vs PRO … Python 2.7 vs 3.6 thing
The ListUsers() function has to be run with the privleges that the SDE user has; not sure why it's set up that way, but I'm running it as the SDE user. If you run it as a non-admin it scolds you that your permissions are not up to snuff.
I add the workspace arg and write the output to a list and step through it with a for loop and get what I want; just an extra step or two than what the help suggests. Seems like the other list type functions I've used have always worked as one expects. This one is flakey, at least for me... (Using arcgis 10.5.1, python 2.x. Looking back at earlier and even the Pro help, they all are the same...)
yeah the code sample isn't clear...but is seems to be a permissions thing... which I guess you would have to check if you can
Joe... Resolved?
Never did...
hmmmm have you asked to have you admin level elevated to 'omnipotent'?
I think I may have come up with a solid solution: you need to be logged in as SDE user AND your'll need an advance license....