Python - pyad 创建名称中带有逗号的用户
Python - pyad create user with a comma in their name
我正在尝试使用 pyad 创建一个用户,我正在做的是:
ou = pyad.adcontainer.ADContainer.from_dn('OU=Employees,DC=lan,DC=company,DC=com')
name = ("doe john")
newUser = pyad.aduser.ADUser.create(name, ou, password="password")
但是,如果我尝试将名称设为 doe, john
(现在有一个逗号):
ou = pyad.adcontainer.ADContainer.from_dn('OU=Employees,DC=lan,DC=company,DC=com')
name = ("doe, john")
newUser = pyad.aduser.ADUser.create(name, ou, password="password")
我收到错误:
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site- packages\pyad\adcontainer.py", line 38, in create_user
obj.SetInfo()
File "<COMObject <unknown>>", line 2, in SetInfo
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Active
Directory', 'An invalid dn syntax has been specified.\r\n', None, 0, -2147016654), None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "NamelyToAD.py", line 49, in <module>
newUser = pyad.aduser.ADUser.create(name, ou, password="Password1")
File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyad\aduser.py", line 16, in create
optional_attributes=optional_attributes
File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyad\adcontainer.py", line 47, in create_user
pyadutils.pass_up_com_exception(e)
File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyad\pyadutils.py", line 58, in pass_up_com_exception
raise WIN32_ERRORS.get(info['error_num'], win32Exception)(error_info=info, additional_info=additional_info)
pyad.pyadexceptions.win32Exception: 0x80072032: An invalid dn syntax has been specified.
我不知道如何解决包括逗号在内的问题,我试过将其转义并包括一个 chr(44),但没有任何效果。
您必须处理两个字符问题:
LDAP 对象 must 的 RDN(例如 cn=User Name
)使用反斜杠对以下字符进行转义:
, \ # + < > ; " =
sAMAccountName
cannot contain以下任一字符:
" [ ] : ; | = + * ? < > / \ ,
pyad
将 by default 尝试将 sAMAccountName
属性设置为传递给 ADUser.create()
的 name
参数,因此,如果禁用字符位于name
,有必要提供您自己的 sAMAccountName
作为可选属性。
在您的示例中,您必须执行以下操作:
pyad.aduser.ADUser.create("Doe\, John", ou, password="Password123",
optional_attributes={'sAMAccountName':'jdoe'})
我正在尝试使用 pyad 创建一个用户,我正在做的是:
ou = pyad.adcontainer.ADContainer.from_dn('OU=Employees,DC=lan,DC=company,DC=com')
name = ("doe john")
newUser = pyad.aduser.ADUser.create(name, ou, password="password")
但是,如果我尝试将名称设为 doe, john
(现在有一个逗号):
ou = pyad.adcontainer.ADContainer.from_dn('OU=Employees,DC=lan,DC=company,DC=com')
name = ("doe, john")
newUser = pyad.aduser.ADUser.create(name, ou, password="password")
我收到错误:
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site- packages\pyad\adcontainer.py", line 38, in create_user
obj.SetInfo()
File "<COMObject <unknown>>", line 2, in SetInfo
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Active
Directory', 'An invalid dn syntax has been specified.\r\n', None, 0, -2147016654), None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "NamelyToAD.py", line 49, in <module>
newUser = pyad.aduser.ADUser.create(name, ou, password="Password1")
File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyad\aduser.py", line 16, in create
optional_attributes=optional_attributes
File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyad\adcontainer.py", line 47, in create_user
pyadutils.pass_up_com_exception(e)
File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyad\pyadutils.py", line 58, in pass_up_com_exception
raise WIN32_ERRORS.get(info['error_num'], win32Exception)(error_info=info, additional_info=additional_info)
pyad.pyadexceptions.win32Exception: 0x80072032: An invalid dn syntax has been specified.
我不知道如何解决包括逗号在内的问题,我试过将其转义并包括一个 chr(44),但没有任何效果。
您必须处理两个字符问题:
LDAP 对象 must 的 RDN(例如
cn=User Name
)使用反斜杠对以下字符进行转义:
, \ # + < > ; " =
sAMAccountName
cannot contain以下任一字符:
" [ ] : ; | = + * ? < > / \ ,
pyad
将 by default 尝试将 sAMAccountName
属性设置为传递给 ADUser.create()
的 name
参数,因此,如果禁用字符位于name
,有必要提供您自己的 sAMAccountName
作为可选属性。
在您的示例中,您必须执行以下操作:
pyad.aduser.ADUser.create("Doe\, John", ou, password="Password123",
optional_attributes={'sAMAccountName':'jdoe'})