I need to get data from a server using LDAP. I'm using ldap3 and am getting all the attributes and responses that I need however, their stuck in the ldap.abstract.entry.entry class. I tried severall methods to get the data into a json or list form but it never worked the way I expected it to work.
For example I tried:
entry = conn.entries
current_data = (entry.entry_to_json())
print(type(current_data))
print(len(current_data))
>>> <class 'str'>
>>> 480
That however, caused all my data to be a single string of length 480 or more. I tried working with this but that just proved to be very difficult. So I tried the following to convert the string to a dict:
current_data = (entry[0].entry_to_json())
current_data = ast.literal_eval(current_data)
print(type(current_data))
print(len(current_data))
>>> <class 'dict'>
>>> 2
However, now I can't access all the different attributes seperately. My goal is to write all of the data that I get from the LDAP Query to a CSV so that other applications can work with it. But currently I'm stuck as I can't get the data into a JSON or CSV format.
How can I get and process the data from the conn.entries
so that I can write each attribute to a seperate column in a CSV?
Best wishes,
C. Zerbe
Edit:
This is a sample of what I get when I use (entry.entry_to_json())
:
{
"attributes": {
"dcxLDOUniqueCN": [
"XXXX"
],
"dcxPostalAddress": [
"XXX"
],
"dcxSupervisor": [
"XXX"
],
"mail": [
"XXX"
],
"mobile": [],
"uid": [
"XXX"
]
},
"dn": "XXX"
}
{
"attributes": {
"dcxLDOUniqueCN": [],
"dcxPostalAddress": [
"XXX"
],
"dcxSupervisor": [
"XXX"
],
"mail": [],
"mobile": [],
"uid": [
"XXX"
]
},
"dn": "XXX"
}