每当我尝试从十六进制转换为 Ascii 时,我都会收到错误消息

I get an error whenever I try to convert from hex to Ascii

这是我的代码

import codecs
m = 61626374667b7273345f69735f61773373306d337
print(m.decode("hex"))

这是我得到的错误,我不确定这是语法中的问题还是我没有很好地使用库。

AttributeError: 'str' object has no attribute 'decode'

此方法来自python2.

如果您想使用编解码器解码字符串,您需要使用:

import codecs

string = "68656c6c6f" #Your string here, between quotation mark
binary_str = codecs.decode(string, "hex")
print(str(binary_str,'utf-8'))

这仍然不起作用,因为您提供了一个包含奇数个字母的十六进制字符串,并且每个 ascii 字母都由 2 个十六进制数字表示,因此请重新检查您的字符串。

(代码来自here)