## Нужны библиотеки pymysql (таблица в которую пишем должна быть в myisam), библиотека ldap3 и re import re import pymysql ## Описываем коннект к ДБ db = pymysql.connect("10.1.6.171","ldap","123456","asterisk" ) cursor = db.cursor() from ldap3 import Server, Connection, SASL, DIGEST_MD5,SUBTREE ##import ldap3 as ldap ##from ldap3 import Connection, Server, SIMPLE, SYNC, SUBTREE, ALL server = Server(host = '10.1.6.180', port = 389) conn = Connection(server, auto_bind = True, version = 3, client_strategy = 'SYNC', authentication = SASL, sasl_mechanism = DIGEST_MD5, sasl_credentials = (None, 'admin', 'Z12345xcvb', None)) #print('test') #print(conn.bind()) #print('test2') user_dn = "cn=admin,ou=users,ou=data,ou=prod,ou=authserver,dc=asterisk,dc=AAA" base_dn = "dc=asterisk,dc=AAA" filter = "uid=admin" total_entries = 0 conn.search(search_base = 'dc=asterisk,dc=AAA', ##search_filter = '(objectClass=inetOrgPerson)', search_filter = '(objectCategory=Person)', search_scope = SUBTREE, attributes = ['title','homePhone'], paged_size = 1000) total_entries += len(conn.response) #result = conn.search(search_base=base_dn, search_filter=filter, search_scope=SUBTREE) #logger.info('SEARCHING COMPLETE') #does not appear in the log # return all user data results try: for entry in conn.response: str1 = entry['attributes'] cont=(str1.get('title')) phone=(str1.get('homePhone')) if cont != [] and phone != [] : ##print('ok') print(f"{cont} {phone}") ins=f"insert into sip(name,host,type,secret,qualify,context) values('{phone}','dynamic','friend','123456','yes','{cont}');" #ins =f"{phone} dsdsds {title}") print(ins) try: cursor.execute(ins) except: print('уже в базе') ##ins=f"insert into tab(p1,p2,p3,p4,p5) values('{str(mass[0])[9:18]}','{extdb}','{caldb}','{td}','{acode}');" except: print("govno") ##print("ERR") conn.unbind()