Python errors QA

python Errors 原因

Q1

1
2
3
4
5
6
7
2019-07-31 17:23:44,663 - jms_perm.py - INFO - perm_key: (['名字(zhi.ming)'], ['v-hostname.hx(10.10.100.100)'])
Traceback (most recent call last):
File "jms_perm.py", line 338, in <module>
perm_args_list = perm_process()
File "jms_perm.py", line 318, in perm_process
long_time_perms[perm_key] = perm
TypeError: unhashable type: 'list'

A1

Python dict的key必须为hashable

问题中key中包含list或dict类型,所以报错.

可哈希的元素有:int, float, str, tuple
不可哈希的元素有:list, set, dict

简单说在元素生命周期中,元素值会发布变动的为unhashable


Q2

报错 ModuleNotFoundError: No module named ‘_ctypes’

A2

其实是缺少了一个新需要的开发包libffi-devel,安装后即可

1
2
3
yum install libffi-devel -y (包在base)
yum install zlib-devel gcc libffi-devel
yum install bzip2-devel readline-devel openssl-devel
坚持原创技术分享,您的支持将鼓励我继续创作!