根据issue https://github.com/Blizzard/heroprotocol/issues/57你提出的,异常发生在Decodes.py 第 69 行 https://github.com/Blizzard/heroprotocol/blob/master/decoders.py#L69:
self._next = ord(self._data[self._used])
这在 Python 2 中成功但在 Python 3 中失败的明显原因是:self._data
是一个字节串。在 Python 2 中,字节串是“标准”字符串对象,因此索引一个字节串会返回该位置的字符(本身就是一个字符串)……
# Python 2.7
>>> b'whatever'[3]
't'
……并打电话ord() https://docs.python.org/2/library/functions.html#ord结果的表现符合预期:
>>> ord(b'whatever'[3])
116
然而,在Python 3中,一切都不同了 https://docs.python.org/3/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit:标准字符串对象是 Unicode 字符串,而字节串则是整数序列。因此,对字节串进行索引会直接返回相关整数......
# Python 3.6
>>> b'whatever'[3]
116
……如此呼唤ord() https://docs.python.org/3/library/functions.html#ord该整数没有意义:
>>> ord(b'whatever'[3])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ord() expected string of length 1, but int found
所以,你应该能够防止specific您在这里询问的异常只需删除对ord()
在那一行和类似的行上:
self._next = self._data[self._used]
…当然,结果可能会揭示更多问题(超出了这个问题的范围)。