
FabioP.19927 (Customer) asked a question.
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())

Hello @FabioP.19927 (Customer) Thank you for reacting out to our Community!
Based on your request I was able to find some similar articles:
https://support.okta.com/help/s/question/0D54z00007OSLlnCAH/expression-language-claims-dont-send-empty-attributes?language=en_US
https://support.okta.com/help/s/article/How-to-search-for-null-and-blank-or-deleted-values-in-attributes-via-API?language=en_US
However I would recommend to to leverage the Okta Developer forums for this type of questions and take advantage of their expertise, as they would have a better understanding on this matter.
https://devforum.okta.com/
Community members help others by clicking Like or Select as Best on responses. Try it today.
Earn Today: New Okta Community Badges Have Arrived
Subscribe Today: The Okta Community is on YouTube
Thank you but I think this doesn't apply as I'm not using the expression language in this case.
Hello @FabioP.19927 (Customer) In this case I would recommend to reach out to our Developer forum as they are the experts on this type or requests.
https://devforum.okta.com/