python - 需要类似字节的对象错误,而不是 'int'
python - Error a bytes-like object is required, not 'int'
我已经阅读了很多答案和文档,但我无法理解问题。
在这段代码中我没有放真正的 HexRegHash 因为我认为它是秘密的。
这是我的代码
HexRegHash= '0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF'
RegHash = binascii.unhexlify(HexRegHash)
UsernameOffset = int(binascii.hexlify(RegHash[0xc]), 16) + 0xcc
Username = RegHash[UsernameOffset:UsernameOffset+UsernameLength].replace('\x00','')
print('Username (offset 0xc): ' + Username + "\n")
这是我的错误。
File "hash2.py", line 94, in <module>
UsernameOffset = int(binascii.hexlify(RegHash[0xc]), 16) + 0xcc
TypeError: a bytes-like object is required, not 'int'
错误只是告诉您 binascii.hexlify(input)
需要二进制数据作为输入。 regHash[0xc]
只是 returns 一个整数,而不是二进制数据。
参见 docs:
binascii.hexlify(data)
Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation. The returned bytes object is therefore twice as long as the length of data.
正确的输入例如是 regHash 本身,或任何其他二进制数据。
对于任何其他帮助,您可能需要解释代码应该做什么以及为什么。
我已经阅读了很多答案和文档,但我无法理解问题。
在这段代码中我没有放真正的 HexRegHash 因为我认为它是秘密的。 这是我的代码
HexRegHash= '0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF0000000000000F3200ACDF'
RegHash = binascii.unhexlify(HexRegHash)
UsernameOffset = int(binascii.hexlify(RegHash[0xc]), 16) + 0xcc
Username = RegHash[UsernameOffset:UsernameOffset+UsernameLength].replace('\x00','')
print('Username (offset 0xc): ' + Username + "\n")
这是我的错误。
File "hash2.py", line 94, in <module>
UsernameOffset = int(binascii.hexlify(RegHash[0xc]), 16) + 0xcc
TypeError: a bytes-like object is required, not 'int'
错误只是告诉您 binascii.hexlify(input)
需要二进制数据作为输入。 regHash[0xc]
只是 returns 一个整数,而不是二进制数据。
参见 docs:
binascii.hexlify(data)
Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation. The returned bytes object is therefore twice as long as the length of data.
正确的输入例如是 regHash 本身,或任何其他二进制数据。 对于任何其他帮助,您可能需要解释代码应该做什么以及为什么。