【问题标题】:Read the null value in Python Redmine API在 Python Redmine API 中读取空值
【发布时间】:2016-05-31 10:45:23
【问题描述】:

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

【问题讨论】:

    标签: openerp redmine redmine-api python-redmine


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的解释
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    相关资源
    最近更新 更多