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

UnicodeEncodeError: 'ascii' codec can't encode characters on non-ascii symbols (cyrillic) in LDAP server on matrix-synapse-ldap3 module #31

Closed
MurzNN opened this issue Jun 28, 2017 · 2 comments

Comments

@MurzNN
Copy link

MurzNN commented Jun 28, 2017

I try to setup Synapse Matrix server with LDAP database (Samba AD server on Linux via Zentyal). After setup it connects successfully, also I can login to Matrix via LDAP login-password, but in user settings "email" field is empty and "Display name" is wrong (equal as login).

Seems that this happens because LDAP user DN and name contains non-ascii unciode symbols (Cyrillic), because I see in logs:

2017-06-28 12:21:42,716 - ldap_auth_provider - 349 - DEBUG - POST-12- Upgraded LDAP connection in search mode through StartTLS: ldap://example.com:389 - cleartext - user: administrator@example.com - unbound - open - <local: xxx.xxx.106.15:58272 - remote: xxx.xxx.36.174:389> - tls started - listening - SyncStrategy - internal decoder
2017-06-28 12:21:42,739 - ldap_auth_provider - 373 - DEBUG - POST-12- LDAP search filter: (&(sAMAccountName=korepov)(userAccountControl=512))
2017-06-28 12:21:42,751 - ldap_auth_provider - 384 - DEBUG - POST-12- LDAP search found dn: CN=Алексей Корепов,CN=Users,DC=office,DC=qseo,DC=ru
2017-06-28 12:21:42,751 - synapse.metrics - 162 - INFO - POST-12- Collecting gc 0
2017-06-28 12:21:42,753 - twisted - 131 - ERROR - POST-12- Traceback (most recent call last):
2017-06-28 12:21:42,753 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/handlers.py", line 76, in emit
2017-06-28 12:21:42,754 - twisted - 131 - ERROR - POST-12-     if self.shouldRollover(record):
2017-06-28 12:21:42,755 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/handlers.py", line 156, in shouldRollover
2017-06-28 12:21:42,755 - twisted - 131 - ERROR - POST-12-     msg = "%s\n" % self.format(record)
2017-06-28 12:21:42,756 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 734, in format
2017-06-28 12:21:42,757 - twisted - 131 - ERROR - POST-12-     return fmt.format(record)
2017-06-28 12:21:42,757 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 465, in format
2017-06-28 12:21:42,758 - twisted - 131 - ERROR - POST-12-     record.message = record.getMessage()
2017-06-28 12:21:42,758 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 329, in getMessage
2017-06-28 12:21:42,759 - twisted - 131 - ERROR - POST-12-     msg = msg % self.args
2017-06-28 12:21:42,759 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/dist-packages/ldap3/core/connection.py", line 308, in __str__
2017-06-28 12:21:42,760 - twisted - 131 - ERROR - POST-12-     'user: ' + str(self.user),
2017-06-28 12:21:42,760 - twisted - 131 - ERROR - POST-12- UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-9: ordinal not in range(128)
2017-06-28 12:21:42,761 - twisted - 131 - ERROR - POST-12- Logged from file ldap_auth_provider.py, line 285
2017-06-28 12:21:42,812 - twisted - 131 - ERROR - POST-12- Traceback (most recent call last):
2017-06-28 12:21:42,812 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/handlers.py", line 76, in emit
2017-06-28 12:21:42,813 - twisted - 131 - ERROR - POST-12-     if self.shouldRollover(record):
2017-06-28 12:21:42,813 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/handlers.py", line 156, in shouldRollover
2017-06-28 12:21:42,814 - twisted - 131 - ERROR - POST-12-     msg = "%s\n" % self.format(record)
2017-06-28 12:21:42,814 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 734, in format
2017-06-28 12:21:42,815 - twisted - 131 - ERROR - POST-12-     return fmt.format(record)
2017-06-28 12:21:42,815 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 465, in format
2017-06-28 12:21:42,816 - twisted - 131 - ERROR - POST-12-     record.message = record.getMessage()
2017-06-28 12:21:42,816 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 329, in getMessage
2017-06-28 12:21:42,817 - twisted - 131 - ERROR - POST-12-     msg = msg % self.args
2017-06-28 12:21:42,817 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/dist-packages/ldap3/core/connection.py", line 308, in __str__
2017-06-28 12:21:42,817 - twisted - 131 - ERROR - POST-12-     'user: ' + str(self.user),
2017-06-28 12:21:42,818 - twisted - 131 - ERROR - POST-12- UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-9: ordinal not in range(128)
2017-06-28 12:21:42,818 - twisted - 131 - ERROR - POST-12- Logged from file ldap_auth_provider.py, line 294
2017-06-28 12:21:42,839 - ldap_auth_provider - 299 - DEBUG - POST-12- LDAP Bind successful in simple bind mode.
2017-06-28 12:21:42,839 - twisted - 131 - ERROR - POST-12- Traceback (most recent call last):
2017-06-28 12:21:42,840 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/handlers.py", line 76, in emit
2017-06-28 12:21:42,840 - twisted - 131 - ERROR - POST-12-     if self.shouldRollover(record):
2017-06-28 12:21:42,841 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/handlers.py", line 156, in shouldRollover
2017-06-28 12:21:42,841 - twisted - 131 - ERROR - POST-12-     msg = "%s\n" % self.format(record)
2017-06-28 12:21:42,842 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 734, in format
2017-06-28 12:21:42,842 - twisted - 131 - ERROR - POST-12-     return fmt.format(record)
2017-06-28 12:21:42,843 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 465, in format
2017-06-28 12:21:42,843 - twisted - 131 - ERROR - POST-12-     record.message = record.getMessage()
2017-06-28 12:21:42,844 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 329, in getMessage
2017-06-28 12:21:42,844 - twisted - 131 - ERROR - POST-12-     msg = msg % self.args
2017-06-28 12:21:42,845 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/dist-packages/ldap3/core/connection.py", line 308, in __str__
2017-06-28 12:21:42,845 - twisted - 131 - ERROR - POST-12-     'user: ' + str(self.user),
2017-06-28 12:21:42,845 - twisted - 131 - ERROR - POST-12- UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-9: ordinal not in range(128)
2017-06-28 12:21:42,846 - twisted - 131 - ERROR - POST-12- Logged from file ldap_auth_provider.py, line 127
2017-06-28 12:21:42,847 - twisted - 131 - ERROR - POST-12- Traceback (most recent call last):
2017-06-28 12:21:42,847 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/handlers.py", line 76, in emit
2017-06-28 12:21:42,847 - twisted - 131 - ERROR - POST-12-     if self.shouldRollover(record):
2017-06-28 12:21:42,848 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/handlers.py", line 156, in shouldRollover
2017-06-28 12:21:42,848 - twisted - 131 - ERROR - POST-12-     msg = "%s\n" % self.format(record)
2017-06-28 12:21:42,849 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 734, in format
2017-06-28 12:21:42,849 - twisted - 131 - ERROR - POST-12-     return fmt.format(record)
2017-06-28 12:21:42,850 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 465, in format
2017-06-28 12:21:42,850 - twisted - 131 - ERROR - POST-12-     record.message = record.getMessage()
2017-06-28 12:21:42,851 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/logging/__init__.py", line 329, in getMessage
2017-06-28 12:21:42,851 - twisted - 131 - ERROR - POST-12-     msg = msg % self.args
2017-06-28 12:21:42,852 - twisted - 131 - ERROR - POST-12-   File "/usr/lib/python2.7/dist-packages/ldap3/core/connection.py", line 308, in __str__
2017-06-28 12:21:42,852 - twisted - 131 - ERROR - POST-12-     'user: ' + str(self.user),
2017-06-28 12:21:42,852 - twisted - 131 - ERROR - POST-12- UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-9: ordinal not in range(128)
2017-06-28 12:21:42,853 - twisted - 131 - ERROR - POST-12- Logged from file ldap_auth_provider.py, line 141
2017-06-28 12:21:42,858 - synapse.handlers.auth - 433 - INFO - POST-12- Logging in user @korepov:example.com on device BCUJZDNXXX

How can I fix this problem?

@MurzNN
Copy link
Author

MurzNN commented Jun 28, 2017

Maybe I can force setup encoding in ldap3 module to UTF-8? I have found a fork of matrix-synapse-ldap3 project with commit slipeer/synapse-ldap-password-provider@0370fbc
Seems it try to add default encoding to matrix-synapse to UTF-8, is this right way?

@MurzNN MurzNN changed the title UnicodeEncodeError: 'ascii' codec can't encode characters on non-ascii symbols (cyrillic) in LDAP server UnicodeEncodeError: 'ascii' codec can't encode characters on non-ascii symbols (cyrillic) in LDAP server on matrix-synapse-ldap3 module Jun 28, 2017
@clokep
Copy link
Member

clokep commented Aug 28, 2020

It seems this is a duplicate of #33.

@clokep clokep closed this as completed Aug 28, 2020
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

2 participants