not sure if its from a plugin update or what but this script used to work. trying to parse fields from an ldap query with the script below and getting the error: Error: the JSON object must be str, bytes or bytearray, not NoneType
script:
def run(params={}):
import json
import datetime
import uuid
user_info = params.get(‘user_info’)
user_dict = json.loads(user_info)
phone_number = user_dict.get('attributes').get('mobile')
other_phone = user_dict.get('attributes').get('telephonenumber')
email_address = user_dict.get('attributes').get('mail')
dn = user_dict.get('attributes').get('distinguishedName')
username = user_dict.get('attributes').get('sAMAccountName')
display_name = user_dict.get('attributes').get('displayName')
upn = user_dict.get('attributes').get('userPrincipalName')
if phone_number is None:
phone_number = ""
# Other vars
date_time = str(datetime.datetime.now())
return {
"phone_number": phone_number,
"other_phone": other_phone,
"email_address": email_address,
"date_time": date_time,
"dn": dn,
"username": username,
"display_name": display_name,
"upn": upn
}
Based on the error, it sounds like this line is failing:
user_dict = json.loads(user_info)
Which means the input to that script was likely blank. Can you check your step input and see if that’s indeed None? If it is look at the step that data is coming from and see if it is failing.
You don’t need to parse the input - it should be passed into your function as a python dict if it’s coming from the ldap plugin.
For example, just change user_info = params.get('user_info')
to user_dict = params.get('user_info')
and delete the user_dict = json.loads(user_info)
line entirely.
In fact, you probably don’t need the python step at all. You can actually access all those properties directly:
If your ldap query step is called “ldap”, and you wanted to access the username of the first object returned, you’d use {{["ldap"].[results].[0].[attributes].[sAMAccountName]}}
If you did a timetime get datetime step to get the current time in addition to the ldap step, you could then use a type convert string to object step with something like this as the input:
{
"phone_number": "{{["ldap"].[results].[0].[attributes].[mobile]}}",
"other_phone": "{{["ldap"].[results].[0].[attributes].[telephonenumber]}}",
"email_address": "{{["ldap"].[results].[0].[attributes].[mail]}}",
"date_time": "date_time{{["Timestamp"].[datetime]}}",
"dn": "{{["ldap"].[results].[0].[dn]}}",
"username": "{{["ldap"].[results].[0].[attributes].[sAMAccountName]}}",
"display_name": "{{["ldap"].[results].[0].[attributes].[displayName]}}",
"upn": "{{["ldap"].[results].[0].[attributes].[userPrincipalName]}}"
}
The output should be the same as your python step, but full disclosure I haven’t tested this handlebars statement yet so there may be a typo in there someplace.