0

使用 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
4

1 回答 1

4

简短的回答:使用getattr(id, 'assigned_to', None)而不是id.assigned_to.

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

于 2016-05-31T19:36:23.587 回答