启用日志记录时,ldap3模块引发UnicodeDecodeError异常

时间:2018-12-19 17:14:24

标签: python logging unicode ldap3

当尝试将更改提交到ldap时,出现以下错误:

Traceback (most recent call last):
  File "popADfields.py", line 216, in <module>
    w.commit()
  File "/usr/local/lib/python2.7/dist-packages/ldap3/abstract/cursor.py", line 770, in commit
    if not entry.entry_commit_changes(refresh=refresh, controls=self.controls, clear_history=False):
  File "/usr/local/lib/python2.7/dist-packages/ldap3/abstract/entry.py", line 601, in entry_commit_changes
    if self.entry_refresh():
  File "/usr/local/lib/python2.7/dist-packages/ldap3/abstract/entry.py", line 637, in entry_refresh
    if self.entry_cursor.refresh_entry(self, tries, seconds):
  File "/usr/local/lib/python2.7/dist-packages/ldap3/abstract/cursor.py", line 870, in refresh_entry
    log(PROTOCOL, 'refreshing entry <%s> for <%s>', entry, self)
  File "/usr/local/lib/python2.7/dist-packages/ldap3/utils/log.py", line 106, in log
    encoded_message = (get_detail_level_name(detail) + ':' + message % args).encode(_logging_encoding, 'backslashreplace')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 37: ordinal not in range(128)

这仅在我打开登录时发生,否则程序运行正常。我使用以下代码打开登录。

from ldap3.utils.log import set_library_log_detail_level, BASIC, ERROR, PROTOCOL
import logging
logging.basicConfig(filename='client_application.log', level=logging.DEBUG)
set_library_log_detail_level(PROTOCOL)

0 个答案:

没有答案
相关问题