How do I convert binary ldap attributes returned by python-ldap to a nice hex representation and back again for use in an ldap filter?
For the task of converting to and from hex string, you should consider the builtin uuid module.
import uuid
object_guid = 'Igr\xafb\x19ME\xb2P9c\xfb\xa0\xe2w'
guid = uuid.UUID(bytes=object_guid)
# to hex
assert guid.hex == '496772af62194d45b2503963fba0e277'
# to human-readable guid
assert str(guid) == '496772af-6219-4d45-b250-3963fba0e277'
# to bytes
assert guid.bytes == object_guid == 'Igr\xafb\x19ME\xb2P9c\xfb\xa0\xe2w'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With