Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing to binary valued attributes does not work #47

Open
steffen-kdab opened this issue Feb 7, 2020 · 0 comments
Open

Writing to binary valued attributes does not work #47

steffen-kdab opened this issue Feb 7, 2020 · 0 comments

Comments

@steffen-kdab
Copy link

I'm trying to write binary data (python type bytes) to a jpegPhoto attribute and get errors:

class User(UserMixin, ldap.Entry):
    ...
    jpegPhoto = ldap.Attribute('jpegPhoto')

jpeg = ... # binary data, bytes type
user.jpegPhoto = jpeg
user.save()

This results in "AttributeError: 'int' object has no attribute 'encode'" in Attribute.get_changes_tuple() because it thinks it's a multi-valued attribute of integers.

jpeg = ... # binary data, bytes type
user.jpegPhoto = [jpeg]
user.save()

A slight improvement, now the data is at least accepted as a single value, error is "AttributeError: 'bytes' object has no attribute 'encode'".

class BytesLDAPHackAdapter(bytes):
    def encode(self, enc):
        return self

jpeg = ... # binary data, bytes type
user.jpegPhoto = [BytesLDAPHackAdapter(jpeg)]

This work-around does the trick by providing a no-op encode member function. But it would be much better if LDAPConn would deal properly with bytes typed data. The problem is that bytes is iterable and not str as far as I can see.

Thank you for a nice library otherwise :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant