运行以下脚本适用于MasterGroupList中60%的条目,但突然失败并出现以下错误。虽然我的问题似乎很差,但是你们之前能够帮助我。知道我怎么能避免这个错误?或者什么是剧本? masterGroupList看起来像:
从AD拉出的团体
SET00 POWERUSER
SET00用户
SEF00创作者
SEF00用户
......另外300个条目......
错误:
Traceback (most recent call last):
File "C:\Users\ks185278\OneDrive - NCR Corporation\Active Directory Access Scr
ipt\test.py", line 44, in <module>
print group.member
File "C:\Python27\lib\site-packages\active_directory.py", line 805, in __getat
tr__
raise AttributeError
AttributeError
代码:
from active_directory import *
import os
file = open("C:\Users\NAME\Active Directory Access Script\MasterGroupList.txt", "r")
fileAsList = file.readlines()
indexOfTitle = fileAsList.index("Groups Pulled from AD\n")
i = indexOfTitle + 1
while i <= len(fileAsList):
fileLocation = 'C:\\AD Access\\%s\\%s.txt' % (fileAsList[i][:5], fileAsList[i][:fileAsList[i].find("\n")])
#Creates the dir if it does not exist already
if not os.path.isdir(os.path.dirname(fileLocation)):
os.makedirs(os.path.dirname(fileLocation))
fileGroup = open(fileLocation, "w+")
#writes group members to the open file
group = find_group(fileAsList[i][:fileAsList[i].find("\n")])
print group.member
for group_member in group.member: #this is line 44
fileGroup.write(group_member.cn + "\n")
fileGroup.close()
i+=1
答案 0 :(得分:0)
免责声明:我不了解python,但我对Active Directory了如指掌。
如果它失败了:
for group_member in group.member:
这可能意味着该组织没有成员。
取决于phython如何处理这个问题,它也可能意味着该组只有一个成员,group.member
是一个普通字符串而不是数组。
print group.member
显示什么?
active_directory.py的源代码位于:https://github.com/tjguk/active_directory/blob/master/active_directory.py
以下是相关内容:
if name not in self._delegate_map:
try:
attr = getattr(self.com_object, name)
except AttributeError:
try:
attr = self.com_object.Get(name)
except:
raise AttributeError
所以看起来它无法找到你正在查找的属性,在这种情况下看起来就像是&#39;成员&#39;属性。