我正在开发一个小型应用程序,以使用ldap3和flask作为前端来更改AD中的用户密码。
它在桌面IDLE中完美运行,并且在AD中更改了密码
我可以在不使用Flask的情况下使其成功运行,但是当我将代码移入flask时,我得到了Indexerror:列表索引超出范围
错误:
第61行条目= 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)