python 3.x - Having trouble getting pyad to work -


i had working before. now, after flatting , rebuilding machine, can't seem pyad working.

my script uses adquery members of domain.

i've installed pyad , pywin32 correct versions. using python 3.6.

i keep getting following error:

pywintypes.com_error: (-2147352567, 'exception occurred.', (0, 'active directory', 'the specified domain either not exist or not contacted.\r\n', none, 0, -2147217865), none)

the script ran before assuming installation issue.

here function wrote:

from pyad import adquery, aduser, adbase  def call_adquery(domain, debug):  global numrow log.info('domain: {}'.format(domain)) df = pd.dataframe() z_obj = adquery.adquery() t = datetime.today().strftime('%m/%d/%y') = 0 if domain == 'satyan':     wc = "mailnickname='satyan'"     domain = 'redmond' else:     wc = """     objectclass='user'     , showinaddressbook='*'     , manager='*'     , not mailnickname='b-*'     """ dn = base_dn = 'ou=useraccounts,dc={0}, dc=corp,dc=microsoft,dc=com'.format(domain) att = ['name', 'displayname', 'title', 'company', 'msexchhidefromaddresslists',        'manager', 'mail', 'mailnickname', 'distinguishedname', 'extensionattribute4',        'extensionattribute2','sn','cn','givenname', 'instancetype','userprincipalname',        'objectcategory'] z_obj.execute_query(attributes=att, where_clause=wc, base_dn=dn, type='gc') row in z_obj.get_results():     += 1     numrow += 1     n = pd.series.from_array(row)     log.info("{0}, {1}, {2}, {3}".format(numrow, i, domain, row['name']))     n['domain'] = domain     n['date'] = t     df = df.append(n, ignore_index=true)     if (debug==true) , (i == 10): break log.info('count {0}: {1}'.format(domain, i)) return df 

not sure why got dinged asking question. maybe that's how stackoverflow works.

i figured out answer , wasn't simple changing domain. andrew appreciate responding sent me down right path.

i spent ton of time debugging this. tried using ldap3 - different python ad library. 1 buggy way faster if had resultset less 1000. never able page searched of more 1000 records - ad limit. eventually, went pyad , figured out problem. pyad easier use module - in humble opinion.

i learned difference between , ldap server , gc server. gc server has ability serve attributes domains in forest. able identify gc server on network using powershell:

> $gcs = get-adforest > $gcs.globalcatalogs 

once had that, set ldap server in pyad:

z_obj.default_ldap_server='xxxx.corp.microsoft.com'   

i removed few attributes query. not sure if factor.

the end results works fine without sending username , password pyad. here code works:

def call_adquery(domain, debug=false):     df = pd.dataframe()     z_obj = adquery.adquery()     = 0     wc = """     objectclass='person'     , samaccounttype='805306368'     , useraccountcontrol='512'     """     dn = 'ou=useraccounts,dc={0},dc=corp,dc=microsoft,dc=com'.format(domain)     att = ['givenname', 'mail', 'manager',             'name',             'displayname','title','mailnickname',             'department','company',             'userprincipalname','sn','cn', 'distinguishedname',             'physicaldeliveryofficename']     z_obj.default_ldap_server='<gc powershell>'      z_obj.execute_query(attributes=att, where_clause=wc, base_dn=dn, type='gc')     df = pd.dataframe()     row in z_obj.get_results():          += 1          if (debug==true) , (i == 10):              break          if len(df)==0:             df =pd.dataframe(row, index=[0])          else:             df= df.append(row, ignore_index=true)      return df 

my guess default active directory server changed , caused fragile code fail.

hope helps else.


Comments

  1. hi! I am having issue as well.
    adquery.py is not working..


    def __init__(self, options={}):
    self.__adodb_conn = win32com.client.Dispatch("ADODB.Connection")
    if self.default_username and self.default_password:
    self.__adodb_conn.Provider = u"ADsDSOObject"
    self.__adodb_conn.Properties("User ID").Value = self.default_username
    self.__adodb_conn.Properties("Password").Value = self.default_password
    adsi_flag = ADQuery.ADS_SECURE_AUTHENTICATION | \
    ADQuery.ADS_USE_ENCRYPTION
    self.__adodb_conn.Properties("ADSI Flag").Value = adsi_flag
    self.__adodb_conn.Properties("Encrypt Password").Value = True
    self.__adodb_conn.Open("")
    else:
    self.__adodb_conn.Open("Provider=ADSDSOObject")

    self.reset()

    Do I have to make any modification to the file?
    Thank you!

    ReplyDelete

Post a Comment

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

javascript - Angular2 intelliJ config error.. Cannot find module '@angular/core' -