Skip to main content
 首页 » 编程设计

python之带有 active_directory 的 Unicode

2025年05月04日7JustinYoung

我正在使用 active_directory模块,并尝试打印用户列表。我的代码是:

import active_directory as ad 
users = ad.AD_Object("LDAP://OU=Home, DC=dome, DC=net") 
for user in users.search(objectCategory="Person"): 
    print str(user) 

它打印一些用户,直到它遇到一个 unicode 用户名。然后它抛出以下错误:

UnicodeEncodeError: ascii codec can't encode characthers in position 10-14: ordinaal not in range(128).

我能做什么?

非常感谢。

请您参考如下方法:

尝试:

print user.decode('utf-8')