2017-09-06 1 views
1

Je la configuration suivante pour LDAP, si j'utilise ldap.SCOPE_SUBTREE, il montre:Python-3.4 Django-v 1.9: problème Ldap - objet module n'a pas d'attribut SCOPE_SUBTREE

ldap3.SCOPE_SUBTREE, "(uid=%(user)s)") 
AttributeError: 'module' object has no attribute 'SCOPE_SUBTREE' 

Si je ldap3.SUBTREE - l'erreur qui apparaît:

File "C:\Python34\lib\site-packages\django_auth_ldap-1.2.13-py3.4.eg\django_auth_ldap\config.py", line 65, in get_ldap 
ImportError: No module named 'ldap.filter' in 

[LDAP-Error.docx](https://github.com/cannatag/ldap3/files/1280858/LDAP-Error.docx) 

code:

#Specify User Profile Model if profile needs to be populated (Optional) 
#AUTH_PROFILE_MODULE = 'account.UserProfile' 

#Baseline configuration. 
AUTH_LDAP_SERVER_URI = "ldap://server ip" 

AUTH_LDAP_BIND_DN = "[email protected]" 
AUTH_LDAP_BIND_PASSWORD = "xxxxxxxxxx" 
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=example,dc=com", 
    ldap3.SUBTREE, "(uid=%(user)s)") 

#AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=users,dc=example,dc=com" 

# Set up the basic group parameters. 

#AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=users,dc=example", 
#  ldap3.SUBTREE,"(objectClass=posixGroup)" 

#) 
#LDAP_AUTH_OBJECT_CLASS = "inetOrgPerson" 
#AUTH_LDAP_GROUP_TYPE = PosixGroupType() 
#group = PUN-GLOBALSUPPORT 
# Simple group restrictions 
#AUTH_LDAP_REQUIRE_GROUP = "cn=enabled,ou=django,ou=groups,dc=example,dc=com" 
#AUTH_LDAP_DENY_GROUP = "cn=disabled,ou=django,ou=groups,dc=example,dc=com" 

#Populate the Django user from the LDAP directory. 
AUTH_LDAP_USER_ATTR_MAP = { 
    "first_name": "givenName", 
    "last_name": "sn", 
    "email": "mail" 
} 

AUTH_LDAP_PROFILE_ATTR_MAP = { 
    "employee_number": "employeeNumber" 
} 

AUTH_LDAP_USER_FLAGS_BY_GROUP = { 
    "is_active": "cn=active,ou=groups,dc=PUN", 
    "is_staff": "cn=staff,ou=groups,dc=PUN", 
    "is_superuser": "cn=superuser,ou=groups,dc=PUN" 
} 

AUTH_LDAP_PROFILE_FLAGS_BY_GROUP = { 
    "is_awesome": ["cn=awesome,ou=groups,dc=PUN"] 
} 

#AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=PUN", 
# ldap.SCOPE_SUBTREE, "(cn=%(user)s)") 
# This is the default, but I like to be explicit. 
AUTH_LDAP_ALWAYS_UPDATE_USER = True 

# Use LDAP group membership to calculate group permissions. 
#AUTH_LDAP_FIND_GROUP_PERMS = True 

# Cache group memberships for an hour to minimize LDAP traffic 
AUTH_LDAP_CACHE_GROUPS = True 
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600 


# Keep ModelBackend around for per-user permissions and maybe a local 
#Configuration for LDAP 
# superuser. 
AUTHENTICATION_BACKENDS = (
    'django_python3_ldap.auth.LDAPBackend', 
    'django_auth_ldap.backend.LDAPBackend', 
    'django.contrib.auth.backends.ModelBackend', 
) 

#Enable Logging method 1 
LOGGING = { 
    "version": 1, 
    "disable_existing_loggers": False, 
    "handlers": { 
     "console": { 
      "class": "logging.StreamHandler", 
     }, 
    }, 
    "loggers": { 
     "django_python3_ldap": { 
      "handlers": ["console"], 
      "level": "INFO", 
     }, 
    }, 
} 
##Enable Logging method 2. Enable debug for ldap server connection 
#logger = logging.getLogger('django_auth_ldap') 
#logger.addHandler(logging.StreamHandler()) 
#logger.setLevel(logging.DEBUG) 
+0

version python rétrogradé à 2,7 et il a travaillé ... –

Répondre

0

J'ai eu le même problème, mais a été en mesure de le réparer à la perfection.

Vous devez copier le package __init__.py du package ldap pour python2 dans le package pour python3.

Trouvez l'emplacement de votre paquet ldap pour python2, disons /site-packages/python2/ldap. Disons aussi le même paquet pour python3 est /site-packages/python3/ldap

Faites ceci:

cp /site-packages/python2/ldap/__init__.py /site-packages/python3/ldap

+0

oui. J'ai fait la même chose. Ça a marché. Merci! –

+0

@SahilSahay s'il vous plaît répondre à ma réponse. – SmallChess