<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z00009zqbaUCAQOkta Classic EngineAPI Access ManagementAnswered2024-02-12T16:02:19.000Z2024-02-09T11:12:29.000Z2024-02-12T16:02:18.000Z

FabioP.19927 (Customer) asked a question.

Okta SDK fails when users have empty attributes

I'm trying to get a list of users using the Okta Python SDK and I'm setting some specific attributes. The problem is the code stops running when it encounters a user with an empty attributes with the error:

"'UserProfile' object has no attribute 'adContainer'". < In this case it listed all users it could find until it found a user with the attribute adContainer empty, then it stops completely instead of just writing the empty value. I'm writing the outputs into a csv using dictWriter so it's supposed to write empty values. Has anyone found a fix for this?

 

**Make sure to first install the okta module via "pip install okta".

import asyncio

import csv

import json

import os

import dotenv

from dotenv import find_dotenv, load_dotenv

from okta.client import Client as OktaClient

from okta.models import UserProfile

 

**Loads .env file containing API_KEY value, change directory to reflect file's location. Enter valid token in the file.

load_dotenv('/Users/fabipazz/Desktop/okta_pagination/users/token.env')

token = os.getenv("API_KEY")

 

*Configure Okta authentication, change org URL as needed and specify up to date token in the .env file.

config = {

  'orgUrl': 'https://itv.okta-emea.com/',

  'token': token

}

okta_client = OktaClient(config)

 

**Query to get only Active users.

query_parameters = {'filter': 'status eq "ACTIVE"'}

 

**Loop to list all active users using the "next" parameters so not to be limited by default 200 results.

**Results are printed, modify to export to csv if needed.

async def main():

  users, resp, err = await okta_client.list_users(query_parameters)

  while True:

    with open("okta_users.csv", "a") as csvfile:

      fieldnames = ['Login', 'Email', 'Title', 'Department', 'Location', 'Organization', 'Ad Container']

      writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

      writer.writeheader()

      for user in users:

        writer.writerow({"Login": user.profile.login, "Email": user.profile.email, "Title": user.profile.title, "Department": user.profile.department, "Location": user.profile.location, "Organization": user.profile.organization, "Ad Container": user.profile.adContainer})

      if resp.has_next():

        users, err = await resp.next()

      else:

        break

loop = asyncio.get_event_loop()

loop.run_until_complete(main())


This question is closed.
Loading
Okta SDK fails when users have empty attributes