<div class="cnblogs_code">
.decode()
上述代码,报错:
'str' object has no attribute 'decode'
查找原因:
https://stackoverflow.com/questions/29030725/str-object-has-no-attribute-decode
You cannot decode string objects; they arealreadydecoded. You'll have to use a different method.
You can use thecodecs.decode()functionto applyhex
as a codec:
>>>>
This applies aBinary transformcodec; it is the equivalent of using thebase64.b16decode()function,with the input string converted to uppercase:
>>>>
You can also use thebinascii.unhexlify()functionto 'decode' a sequence of hex digits to bytes:
>>>>
Either way,you'll get abytes
object.
使用第二种方式解决了:
>>> >>> base64.b16decode()