Flask ldap3 登录问题

Flask ldap3 issue with login

我在 Flask 中使用 Ldap3 python。
我在尝试登录时遇到错误:

TypeError: Object of type 'Attribute' is not JSON serializable

代码如下:

def ADlogin(username,password):
    server = ldap3.Server(server_uri, get_info=ldap3.ALL)
    connection = ldap3.Connection(server, user=username+base, password=password)
    if not connection.bind():
        return False
    else:
        connection.search(username+base, '(objectClass=*)', attributes=ldap3.ALL_ATTRIBUTES)
        session['username'] = username
        session['uid'] = connection.entries[0].uid
        connection.search('dc=example,dc=com', '(objectclass=posixGroup)',
                          attributes=[ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES])
        for entry in connection.entries:
            if entry.cn == 'service':
                for user in entry.memberUid:
                    if user == session['uid']:
                        session['group_service'] = True
                        break
            elif entry.cn == 'management':
                for user in entry.memberUid:
                    if user == session['uid']:
                        session['group_management'] = True
                        break
        return True

和登录页面:

@app.route("/login", methods=['GET', 'POST'])
def login():
    if request.method == "POST" and request.form['submit'] == "Sign in":
        username = request.form['username']
        password = request.form['password']
        if utils.isEmpty(username) or utils.isEmpty(password):
            return render_template('login.html', status="Please Enter All Fields")

        else:
            status = ADConnect.ADlogin(username,password)
            if status:
                #return redirect(url_for('dashboard'))
                return "Success"
            else:
                return render_template('login.html', status=status)



    else:
        return render_template('login.html')

代码在 python 控制台中运行良好,但是当我用 flask 尝试它时它显示错误,我无法找到问题的解决方案。

查找错误原因:

这是行或错误:session['uid'] = connection.entries[0].uid

connection.entries[0].uid 属于 ATTRIBUTE 类型,我正试图在导致错误的会话中设置它。

我将属性类型更改为字符串,现在可以使用了!