我使用的是Ldap3和。
当我尝试登录时,我收到了错误:
TypeError:类型为“Attribute”的对象不能被JSON序列化
以下是代码:
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控制台中运行良好,但是当我用烧瓶尝试它时,它显示了错误,我无法找到问题的解决方案。
发布于 2019-03-12 11:32:53
找出错误的原因:
下面是行或错误:会话‘’uid‘= connection.entries.uid
connection.entries.uid是类型属性,我试图在会话中设置它,导致错误。
我将属性类型更改为string,它现在起作用了!
https://stackoverflow.com/questions/54998220
复制相似问题