bz2
使用 Python使用模块加密密码时出现以下错误。在这里,我将加密值保存在 DB 中。
错误:
ProgrammingError at /signsave/
You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.
Request Method: POST
Request URL: http://127.0.0.1:8000/signsave/
Django Version: 1.11.2
Exception Type: ProgrammingError
Exception Value:
You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.
这是我的代码:
def signsave(request):
"""This function helps to save signup data"""
if request.method == 'POST':
name = request.POST.get('uname')
password = request.POST.get('pass')
con_pass = request.POST.get('conpass')
new_pass = bz2.compress(password)
if password == con_pass:
passw = User(
uname=name,
password=new_pass,
raw_password=password,
)
passw.save()
message = "Registered successfully"
return render(request, 'bookingservice/login.html', {'msg': message})
else:
message = "The password did not match "
return render(request, 'bookingservice/signup.html', {'msg': message})
在这里,当我尝试保存加密值时,这些错误即将到来。