3.0の「hashlib」モジュールに関する問題
-
19-08-2019 - |
質問
私が立ち往生得ているとき、
私は、主に私自身の教育のため、3.0に移植2.5モジュールを得ることに取り組んできました。クラス「ビルダー」そのINITとして持っています:
def __init__(self, **options):
self._verifyOptions(options)
self._options = options
self._initDigest()
self._initBuildNames()
self._methods = []
しかし、エラーがで発生ます:
def _initDigest(self):
import os, sys, hashlib
digester = hashlib.md5()
digester.update(self._options.get('code'))
self._digest = digester.hexdigest()
そのトレースバックとして持っていた。
Traceback (most recent call last):
File "<pyshell#5>", line 5, in <module>
""", language="Cee")
File "C:\Python30\lib\site-packages\PyInline\__init__.py", line 31, in build
b = m.Builder(**args)
File "C:\Python30\lib\site-packages\PyInline\Cee.py", line 17, in __init__
self._initDigest()
File "C:\Python30\lib\site-packages\PyInline\Cee.py", line 27, in _initDigest
digester.update(self._options.get('code'))
TypeError: object supporting the buffer API required
私は2to3はを通してそれを実行しましたが、それはそれを拾っていません。私の知る限り、アップデート機能は、バイト/バッファの形態であることへの引数を期待しているが、私はそれを変換するために、いくつかの異なる方法を試してきましたし、成功していない。
いつものように、どのような援助を大幅に理解されるであろう。 :)
解決
私はこの行を推測しています
digester.update(self._options.get('code'))
となります。
digester.update(self._options.get('code').encode("utf-8"))
実際の所望の符号化は、あなたのケースで異なるかもしれないが、UTF-8は、すべてのケースで動作します。
他のヒント
私はまだ3.0を試してみましたhavent。しかし、今のバイトと文字列の配列との間に大きな違いがあります。かつて、後者ホールドUnicodeのコードポイントは、Unicodeだけencoded
Unicode文字列を保持していません。ハッシュはバイトのシーケンスで動作します。だから、最初のハッシュにそれらを供給bevoreます。
所属していません StackOverflow