''.decode('hex')

上述代码,报错:

'str' object has no attribute 'decode'

查找原因:

https://stackoverflow.com/questions/29030725/str-object-has-no-attribute-decode

You cannot decode string objects; they are already decoded. You'll have to use a different method.

You can use the codecs.decode() function to apply hex as a codec:

>>> import codecs
>>> codecs.decode('ab', 'hex')
b'\xab'

This applies a Binary transform codec; it is the equivalent of using the base64.b16decode() function, with the input string converted to uppercase:

>>> import base64
>>> base64.b16decode('AB')
b'\xab'

You can also use the binascii.unhexlify() function to 'decode' a sequence of hex digits to bytes:

>>> import binascii
>>> binascii.unhexlify('ab')
b'\xab'

Either way, you'll get a bytes object.

使用第二种方式解决了:

>>> import base64
>>> base64.b16decode('AB')

最新文章

  1. SQL 约束
  2. [转]在 Web 项目中应用 Apache Shiro
  3. android 学习资源总结
  4. JavaScript基础插曲—获取标签,插入元素,操作样式
  5. COJ 删除数字
  6. bzoj 1012 维护一个单调数列
  7. javaSE第十三天
  8. android 多语言版本开发
  9. php错误处理和异常处理
  10. Linux目录结构及文件基础操作
  11. Windows Phone 8初学者开发—第14部分:在运行时绑定到真实的数据
  12. SQL server 表数据改变触发发送邮件
  13. WordPress 邮箱防抓取
  14. HTML做的网页 如何使当前页面跳转到另一页面锚点处
  15. Expm 10_2 实现Ford-Fulkerson算法,求出给定图中从源点s到汇点t的最大流,并输出最小割。
  16. awd入门教程
  17. 遍历一个Set的方法只有一个:迭代器(interator)。
  18. Vue 中使用 viewerjs
  19. 国外青少年最喜爱的聊天 app,竟然是 Google Docs
  20. Oracle的简单的创建dblink以及进行数据迁移的方法

热门文章

  1. Codeforces 645A Amity Assessment【八数码】
  2. 51Nod——T 1686 第K大区间
  3. Linux系统备份还原工具4(rsync/远程数据同步工具)
  4. pymongo collection.save 问题
  5. hbase definitive guide 笔记
  6. Serv-u 10.3 的图文安装教程及使用方法
  7. 踩坑录-mysql不允许远程连接(错误码:1130) Host'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server“
  8. Elasticsearch学习系列之mapping映射
  9. hive中使用正則表達式不当导致执行奇慢无比
  10. [Canvas画图] 藏图阁(16) 人体穴位