Python无法腌制ZabbixAPI类实例

时间:2015-01-22 00:40:38

标签: python

我无法使用以下代码挑选pyzabbix.ZabbixAPI类实例:

from pyzabbix import ZabbixAPI
from pickle import dumps

api = ZabbixAPI('http://platform.autuitive.com/monitoring/')

print dumps(api)

导致以下错误:

Traceback (most recent call last):
  File "zabbix_test.py", line 8, in <module>
    print dumps(api)
  File "/usr/lib/python2.7/pickle.py", line 1374, in dumps
    Pickler(file, protocol).dump(obj)
  File "/usr/lib/python2.7/pickle.py", line 224, in dump
    self.save(obj)
  File "/usr/lib/python2.7/pickle.py", line 306, in save
    rv = reduce(self.proto)
  File "/usr/lib/python2.7/copy_reg.py", line 84, in _reduce_ex
    dict = getstate()
TypeError: 'ZabbixAPIObjectClass' object is not callable

1 个答案:

答案 0 :(得分:1)

嗯,在documentation中说:

  

__dict__或调用结果的类的实例   __getstate__()是可挑选的(有关详细信息,请参阅pickle协议一节)。

看来这个班级不是一个。如果你真的需要这样做,那么考虑编写你自己的酸洗程序。