我正在开发一个小型应用程序,以使用 ldap3 和烧瓶作为前端更改 AD 中的用户密码。
它在桌面 IDLE 中完美运行,密码在 AD 中更改
我可以在不使用 Flask 的情况下使其成功运行,但是当我将代码移动到烧瓶中时,我得到一个 Indexerror: List index out of range
错误:
第 61 行 entry = conn.entries[0] user_dn = str(entry.distinguishedName)
r = conn.extend.microsoft.modify_password(user_dn, pwd)
IndexError: list index out of range
from ldap3 import Server, Connection, ALL, NTLM
import ldap3
from flask import render_template, redirect, Flask, request, url_for
import time
import datetime, os
import smtplib
timestr = time.strftime("%Y-%m-%d")
app = Flask(__name__)
app.config['SECRET_KEY'] = os.urandom(24).hex()
def get_user_email(user):
user = user
#Connect to Server
server = Server('server.com', use_ssl=True, get_info=ALL)
conn = Connection(server, user='domain\\adminuser', password='adminpassword', authentication=NTLM, auto_bind=True)
dn = "OU=CON1,OU=CON2,OU=CONT3,DC=domain,DC=suf1,DC=ct,DC=suf2"
conn.search(dn, '(&(objectClass=user)(userPrincipalName='+user+'@domain.suf1.suf2))',attributes=['*'])
entry = conn.entries[0]
user_dn = entry.distinguishedName
return entry.mail
@app.route('/')
def index():
return render_template('index.html')
@app.route('/myaccount', methods = ['POST', 'GET'])
def myaccount():
if request.method == 'POST':
user_name = request.form['user_name']
return render_template('found.html',user_name=get_user_email(user_name))
return 'Account Not Found'
@app.route('/changepw', methods = ['POST', 'GET'])
def changepw():
if request.method == 'POST':
user_name = request.form['user_name']
pwd = request.form['pwd']
print(user_name)
change_pw(user_name,pwd)
return 'Success'
return redirect(url_for('index'))
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=8080)