我正在尝试使用pyad更新Active Directory中的用户属性。这是我的代码
from pyad import *
pyad.set_defaults(ldap_server="server.domain.local",
username="admin", password="password")
pyad.adobject.ADObject.update_attribute(self='testuser1', attribute='mail',
newvalue='my@email.com')这是我收到的错误。
Traceback (most recent call last):
File "c:\Users\Administrator\Desktop\scripts\AD-Edit-user.py", line 12, in
<module>
pyad.adobject.ADObject.update_attribute(self='testuser1', attribute='mail',
newvalue='my@email.com')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-
32\lib\site-packages\pyad-0.5.20-py3.6.egg\pyad\adobject.py", line 318, in
update_attribute
elif pyadutils.generate_list(newvalue) != self.get_attribute(attribute):
AttributeError: 'str' object has no attribute 'get_attribute'这使我假设我需要将属性类型从str更改为其他类型。我已经验证了mail是正确的属性名称。
我知道ldap连接正在工作,因为我可以使用类似的脚本创建用户。
发布于 2018-02-15 03:33:47
你的问题是如何使用pyad。特别是在这一行中:
pyad.adobject.ADObject.update_attribute(self='testuser1', attribute='mail',
newvalue='my@email.com')如果我们查看source of pyad.adobject.ADObject,我们可以看到以下内容:
def update_attribute(self, attribute, newvalue, no_flush=False):
"""Updates any mutable LDAP attribute for the object. If you are adding or removing
values from a multi-valued attribute, see append_to_attribute and remove_from_attribute."""
if newvalue in ((),[],None,''):
return self.clear_attribute(attribute)
elif pyadutils.generate_list(newvalue) != self.get_attribute(attribute):
self._set_attribute(attribute, 2, pyadutils.generate_list(newvalue))
if not no_flush:
self._flush()这里的self不是函数的参数,它是对类实例的引用。您的呼叫包括str格式的self='testuser1'。
请查阅有关如何使用此函数/功能/模块here的文档。你会注意到没有“自我”...除了查看源代码之外,我不确定您是如何得出您需要self的结论的。
我无法测试以下内容,但这是它应该如何工作的大致方式:
# first you create an instance of the object, based on
# the distinguished name of the user object which you
# want to change
my_ad_object = pyad.adobject.ADObject.from_dn('the_distinguished_name')
# then you call the update_attribute() method on the instance
my_ad_object.update_attribute(attribute='mail', newvalue='my@email.com')https://stackoverflow.com/questions/48794251
复制相似问题