【Python】AttributeError: 'UUID' object has no attribute 'get_hex'

友情提醒:本文最后更新于 1529 天前,文中所描述的信息可能已发生改变,请谨慎使用。

一、起因

因为之前把博客从Python2.7升级到了python3.6,所以之前的上传图片到七牛云存储的方法突然报以下错误:

AttributeError: 'UUID' object has no attribute 'get_hex'

二、解决办法

python3之后uuid获取十六进制的方法有所改变

import uuid
-  key = uuid.uuid4().get_hex()  # python2
+  key = uuid.uuid4().hex  # python3

上一篇:Docker实现本地镜像的导入、导出

下一篇:Linux tar压缩和解压缩命令详解