I am using the below code to poll users from an Active Directory User Source, pulling the schedules from a second internal User Source, and then merge the two. When I test this script on my local ignition setup it runs without an issue (only a handful of users). When I run it on my production ignition setup it get the 'NoneType' object has no attribute 'get' for some reason.
#grab all users from Active Directory. I called the "User Source" domain2
domainUsers = system.user.getUsers("DomainSource")
for user1 in domainUsers:
# if user already exists in internal "User Source"
try:
# get the user from internal "User Source". I called it NewProfile. Will be used later to grab the schedule
userInternal = system.user.getUser("InternalSource", str(user1.get("username")))
if (userInternal.get("Schedule") <> "Always"):
# get schedule from internal User Soucr and set it to currently selected domain user
user1.set("Schedule", userInternal.get("Schedule"))
# remove the user from internal "User Source" schedule to allow contact info to populate correctly
system.user.removeUser("InternalSource", user1.get("username"))
finally:
# add user from domain "User Source" to internal "User Source"
system.user.addUser("InternalSource", user1)
My fault for not reading the full post first. You're trying to get users from the AD user source into an internal user source right, not the other way around?
Either way, a NoneType issue here makes it seem like you ran into a user who exists in one user source but not the other. Give you use a finally it seems like it should still probably add the user but you will get an error for each user that exists in AD but not in the Internal, is that what your experiencing?
I would probably make the script more like this -
domainUsers = system.user.getUsers("DomainSource")
for user1 in domainUsers:
# if user already exists in internal "User Source"
try:
# get the user from internal "User Source". I called it NewProfile. Will be used later to grab the schedule
userInternal = system.user.getUser("InternalSource", str(user1.get("username")))
if (userInternal.get("Schedule") <> "Always"):
# get schedule from internal User Soucr and set it to currently selected domain user
user1.set("Schedule", userInternal.get("Schedule"))
# remove the user from internal "User Source" schedule to allow contact info to populate correctly
system.user.removeUser("InternalSource", user1.get("username"))
except AttributeError, e:
# user doesn't exist in Internal source, chance to set default schedule and add user etc
system.user.addUser("InternalSource", user1)
```
The specific user you had an error for. Manually check. I would think that user name exists in AD but not in your internal. Check my little script change. I would use the NoneType error as your cue that the user exists in AD but not internal and do your adding there, not in a finally clause.
It's weird because I tested that issue on my local setup and it works properly if a user exists in one User Source but not the other. I'll give your code a try and let you know.
The error is occurring on Line 9, which means that userInternal is None. It also appears to have worked many times prior to the error, which would indicate it's not finding a specific user.
Perhaps add this for trouble shooting:
if userInternal and (userInternal.get('Schedule') <> 'Always'):
#do stuff
else:
print userName