+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

使用pyad创建新的Active Directory用户

发布于2021-04-10 10:02     阅读(2537)     评论(0)     点赞(4)     收藏(1)


0

1

2

3

4

5

6

7

8

9

我在udemy完成了在线课程,现在我尝试了一些东西,我需要pyad的帮助,试图在虚拟机中创建活动目录用户(该代码也在该计算机上)看起来在线,并且看起来一对一完美,但是突然我得到了错误,

此代码错误:

from pyad import *

pyad.set_defaults(ldap_server="DC-01-Training.Udemy.training",username="Administrator",password="abc-123")

#test create new user
user = "pyadtest"
ou = pyad.adcontainer.ADContainer.from_dn("ou=Users,dc=Udemy,dc=Training")
new_user = pyad.aduser.ADUser.create(user,ou,password="abc-123")

错误:

---------------------------------------------------------------------------
com_error                                 Traceback (most recent call last)
<ipython-input-40-c8119c8ee0d8> in <module>
     17 #test create
     18 user = "pyadtest"
---> 19 ou = pyad.adcontainer.ADContainer.from_dn("ou=Users,dc=Udemy,dc=Training")
     20 new_user = pyad.aduser.ADUser.create(user,ou,password="abc-123")
     21 

C:\ProgramData\Anaconda3\lib\site-packages\pyad\adobject.py in from_dn(cls, distinguished_name, options)
    129     def from_dn(cls, distinguished_name, options={}):
    130         "Generates ADObject based on distinguished name"
--> 131         return cls(distinguished_name, None, options)
    132 
    133     @classmethod

C:\ProgramData\Anaconda3\lib\site-packages\pyad\adobject.py in __init__(self, distinguished_name, adsi_ldap_com_object, options)
     86                             self.default_ldap_port
     87             )
---> 88             self.__set_adsi_obj()
     89         else:
     90             raise Exception("Either a distinguished name or a COM object must be provided to create an ADObject")

C:\ProgramData\Anaconda3\lib\site-packages\pyad\adobject.py in __set_adsi_obj(self)
     51                 if self.default_ssl:
     52                     flag = flag | ADS_AUTHENTICATION_TYPE['ADS_USE_ENCRYPTION']
---> 53             self._ldap_adsi_obj = _ds.OpenDSObject(
     54                     self.__ads_path,
     55                     self.default_username,

C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py in OpenDSObject(self, *args)

com_error: (-2147352567, 'Exception occurred.', (0, 'Active Directory', 'There is no such object on the server.\r\n', None, 0, -2147016656), None)

``


解决方案


在您的代码中显示:

ou = pyad.adcontainer.ADContainer.from_dn("ou=Users,dc=Udemy,dc=Training")

应该在哪里:

ou = pyad.adcontainer.ADContainer.from_dn(ou="Users",dc="Udemy",dc="Training")

0

1

2

3

4

5

6

7



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/929675/afeef313c41ee353a38a/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

4 0
收藏该文
已收藏

评论内容:(最多支持255个字符)