加入收藏 | 设为首页 | 会员中心 | 我要投稿 莱芜站长网 (https://www.0634zz.com/)- 云连接、建站、智能边缘云、设备管理、大数据!
当前位置: 首页 > 编程开发 > Python > 正文

python2 str object has no attribute decode

发布时间:2020-07-29 10:48:36 所属栏目:Python 来源:互联网
导读:0102030405060708.decode(hex)上述代码,报错:str object has no attribute decode查找原因:https://stackoverflow.com/questions/29030725/str-object-has-no-attribute-decodeYou cannot decode string objects; they arealreadydecoded. Youll have to u

<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 applyhexas 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 abytesobject.

使用第二种方式解决了:

>>> >>> base64.b16decode()

(编辑:莱芜站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读