• 0

Syntax Error in Python Script


Question

I have the following script that pulls in users from the Active Directory and creates accounts in Zimbra. I have the following error

Invalid Syntax it is saying this on line 13

for (dn, vals) in res:

I am new to python and have heard that it can be somewhat funny about indentation?

I would welcome any advice on were I might be going wrong.

#!/usr/bin/python
# This file is covered by GNU GPL.

import ldap, string, os

domain = "lordswoodgirls.school"
l=ldap.initialize("ldap://server.example.com":389") # pick an LDAP server
l.simple_bind_s("domain\\ldap_username","ldap_password")
try:
  res = l.search_s('ou=students,dc=example,dc=com',
  ldap.SCOPE_SUBTREE, "(&(ObjectCategory=user) (userAccountControl=512))", ['sAMAccountName','givenName','sn']
  #userAccountControl  512 = normal , 514 = disabled account
	for (dn, vals) in res:
	accountname = vals['sAMAccountName'][0].lower()
	try:
	  sirname = vals['sn'][0].lower()
	except:
	  sirname = vals['sAMAccountName'][0].lower()
	try:
	  givenname = vals['givenName'][0]
	except:
	  givenname = vals['sAMAccountName'][0].lower()

	initial = givenname[:1].upper()
	sirname = sirname.capitalize()
	name = initial + "." + sirname
	accountname = accountname + "@" + domain
	password = "  \'\' "
	print password
	print accountname,name
	os.system('echo command ca %s \'\' displayName %s' % (accountname,name))

except ldap.LDAPError, error_message:
  print error_message

l.unbind_s()

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.