<p>我正在调用<code>bcrypt.checkpw</code>以检查未加密的密码是否与存储在凭据数据库中的哈希密码匹配,但接收</p>
<blockquote>
<p>TypeError: Unicode-objects must be encoded before checking</p>
</blockquote>
<p>我该如何解决这个问题?有什么建议吗?<br/>
我安装了<code>python 2.7.6</code>,和<code>bcrypt 3.1.1</code></p>
<p>我有以下代码:</p>
<pre><code>def check_password(password, hashed_password)
if not bcrypt.checkpw(password, hashed_password):
raise InvalidCredentials("403 Forbidden")
else:
return true
</code></pre>
<p>并收到以下错误:</p>
<blockquote>
<p>File "/home/qt/virtualenv/lib/python2.7/site-packages/bcrypt/<strong>init</strong>.py", line 100, in checkpw<br/>
raise TypeError("Unicoed-objects must be encoded before checking")<br/>
TypeError: Unicode-objects must be encoded before checking</p>
</blockquote>
<p>我调查过<code>bcrypt/__init__.py</code>,但我不知道为什么</p>
<pre><code>def checkpw(password, hashed_password):
if (isinstance(password, six.text_type) or
isinstance(hashed_password, six.text_type)):
raise TypeError("Unicode-objects must be encoded before checking")
</code></pre>