gpt4 book ai didi

python - 关于 3. 0's "hashlib"模块的问题

转载 作者:太空宇宙 更新时间:2023-11-03 23:51:07 25 4
gpt4 key购买 nike

我一直在努力将 2.5 模块移植到 3.0,主要是为了我自己的教育,当我遇到困难时。 “Builder”类的初始值是:

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 将适用于所有情况。

关于python - 关于 3. 0's "hashlib"模块的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/343204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com