读取Python Redmine API中的null值

时间:2016-05-31 10:45:24

标签: openerp redmine redmine-api python-redmine

使用rest API,我将Redmine与Python脚本连接并在ODOO中填充数据。

在Redmine中,assigned_to中的值为空,即NULL,同时读取这些值。

Traceback (most recent call last):
  File "/home/vignesh/PycharmProjects/vignesh/vigred.py", line 23, in <module>
    redmine_asssigned_to = id.assigned_to
  File "/usr/local/lib/python2.7/dist-packages/python_redmine-1.5.1-py2.7.egg/redmine/resources.py", line 424, in __getattr__
    return super(Issue, self).__getattr__(item)
  File "/usr/local/lib/python2.7/dist-packages/python_redmine-1.5.1-py2.7.egg/redmine/resources.py", line 193, in __getattr__
    return self._action_if_attribute_absent()
  File "/usr/local/lib/python2.7/dist-packages/python_redmine-1.5.1-py2.7.egg/redmine/resources.py", line 294, in _action_if_attribute_absent
    raise ResourceAttrError
redmine.exceptions.ResourceAttrError: Resource doesn't have the requested attribute

1 个答案:

答案 0 :(得分:2)

简答:使用getattr(id, 'assigned_to', None)代替id.assigned_to

答案很长:如果您尝试访问不存在的属性,Python-Redmine会引发ResourceAttrError。这里的问题是assigned_to可能存在或者可能不存在于资源对象上,具体取决于它是否在Redmine中设置,而且Python-Redmine也不对其自身内部的任何属性进行硬编码,即它从Redmine动态获取它们,这就是你遇到这个问题的原因。