Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

AttributeErrorNoneTypeobjecthasnoattributedecode

i'm trying to sync zabbix with ldap using python script but i have a problem
of AttributeError: 'NoneType' object has no attribute 'decode' which exists in the part the making the users as shown below

 def sync_users(self):
    """
    Syncs Zabbix with LDAP users
    """

    self.ldap_conn.connect()
    zabbix_all_users = self.get_users()

    for eachGroup in self.ldap_groups:

        ldap_users = self.ldap_conn.get_group_members(eachGroup)

        # Do nothing if LDAP group contains no users and "--delete-orphans" is not specified
        if not ldap_users and not self.deleteorphans:
            continue

        zabbix_grpid = [g['usrgrpid'] for g in self.get_groups() if g['name'] == eachGroup].pop()

        zabbix_group_users = self.get_group_members(zabbix_grpid)

        missing_users = set(list(ldap_users.keys())) - set(zabbix_group_users)

        # Add missing users
        for eachUser in missing_users:

            # Create new user if it does not exists already
            if eachUser not in zabbix_all_users:
                self.logger.info('Creating user "%s", member of Zabbix group "%s"' % (eachUser, eachGroup))
                user = {'alias': eachUser}
                user['name'] = self.ldap_conn.get_user_givenName(ldap_users[eachUser]).decode("utf-8")
                user['surname'] = self.ldap_conn.get_user_sn(ldap_users[eachUser]).decode("utf-8")

                if user['name'] is None:
                    user['name'] = ''
                if user['surname'] is None:
                    user['surname'] = ''

                self.create_user(user, zabbix_grpid, self.user_opt)
                zabbix_all_users.append(eachUser)
            else:
                # Update existing user to be member of the group
                self.logger.info('Updating user "%s", adding to group "%s"' % (eachUser, eachGroup))
                #self.create_user(user, zabbix_grpid, self.user_opt)

Comments