AnsweredAssumed Answered

create users sample keeps hitting 500 error?

Question asked by jgustine on Apr 13, 2018
Latest reply on Oct 3, 2018 by RandySincoular

I modified the create users functions from the Clone portal sample to create users in our new stack from the old portal. The script seems good, works for a few users then starts hitting 500 errors all the others (600+). 



java.lang.Exception: The server at '' returned an error. Unable to signup user. ["Unable to add user."]
(Error Code: 500)


Anybody have any ideas what I might be doing wrong? I thought it was a certificate issue, but that looks ok.


Thanks for any input! 


from arcgis.gis import GIS
source_password = '*'
target_password = '*'
source = GIS("", "arcgisportaladmin", source_password)
target = GIS("", "arcgisportaladmin", target_password)
target_admin_username = 'arcgisportaladmin'

source_users ='!esri_ & !arcgisportaladmin', max_users=700)
for user in source_users:
    print(user.username + "\t:\t" + str(user.role)+  "\t:\t" +  str(user.idpUsername))

print (len(source_users))

# filter out system and initial administrator accounts
target_users ='!esri_ & !arcgisportaladmin & !system_publisher', max_users=700)
print (target_users)

for source_user in source_users:
        target_user = target.users.get(source_user.username)
        if target_user is not None:
            print('Deleting user: ' + target_user.fullName)
        print('User {} does not exist in Target Portal'.format(source_user.username))

def copy_user(target_portal, source_user, pw):
    # See if the user has firstName and lastName properties
        first_name = source_user.firstName
        last_name = source_user.lastName
        # if not, split the fullName
        full_name = source_user.fullName
        first_name = full_name.split()[0]
            last_name = full_name.split()[1]
            last_name = 'NoLastName'

    source_level = source_user.level
    if source_level == str("1"):
        source_role = 'org_viewer'
    if source_level == str("2"):
        source_role = 'org_user'
    if source_user.provider == 'enterprise':
        source_password = None
    if source_user.provider == 'arcgis':
        source_password = pw

        # create user
        target_user = target_portal.users.create(username =,
                            firstname = first_name,
                            lastname = last_name,
                            email =,
                            role =source_role,
                            provider =source_user.provider, level=source_level, password=source_password)

        # update user properties
        target_user.update(source_user.access, source_user.preferredView,
                           source_user.description, source_user.tags,
                           culture=source_user.culture, region=source_user.region)

        return target_user
    except Exception as Ex:
        print("Unable to create user "+ source_user.username)
        return None

for user in source_users:
    print("Creating user: " + user.username)
    copy_user(target, user, 'TestPassword@123')