首页 > 解决方案 > 无法使用 pyral 的 rest api python 提取项目的所有特征数据

问题描述

我正在尝试使用 pyral 模块读取 Rally 中项目的所有特征数据。结果集总数为 1358,脚本在读取约 700 条记录后抛出如下所述的错误。

rally1 = Rally(entity='PortfolioItem_Feature',server='rally1.rallydev.com',fetch=True, user='xxx', password='', workspace='xxx/yyy', project='ABC')
features = rally1.get('Feature',fetch="True",pagesize=2000,start=0,limit=5000)

for feature in features:
    #a=pd.DataFrame(feature)
    print(feature.details())

输出:

PortfolioItem/Feature result set, totalResultSetSize: 1358, startIndex: 1  pageSize: 2000  current Index: 0
I'm getting the following errors:

File "C:\Users\nis\AppData\Roaming\Python\Python38\site-packages\pyral\entity.py", line 397, in details
    (attr_name, cln, value.oid, value.UserName, value.DisplayName)
  File "C:\Users\nis\AppData\Roaming\Python\Python38\site-packages\pyral\entity.py", line 139, in __getattr__
    raise UnreferenceableOIDError("%s OID %s" % (rallyEntityTypeName, self.oid))
pyral.entity.UnreferenceableOIDError: User OID 44012386960

所以,我有以下问题:

  1. 如何修复此错误,这意味着跳过读取特征属性的特定字段或将其替换为空结果集。
  2. 如何将 (a) <class 'pyral.rallyresp.RallyRESTResponse'> (b) PortfolioItem/Feature 结果集转换为数据框而不会出现上述错误。

我正在使用下面的代码,这个脚本也读了大约。700 条记录并引发与上述相同的错误。我尝试使用错误处理,但它在遇到错误时停止读取。任何帮助将不胜感激。

r=pd.DataFrame()
for feature in features:
 a= {
 'OID': feature.oid,
 'FeatureID':feature.FormattedID,
 'Creation_Date': feature.CreationDate,
  'Project_Name': feature.Project.Name,
  'AcceptedLeafStoryPlanEstimateTotal':feature.AcceptedLeafStoryPlanEstimateTotal,
  'AcceptedLeafStoryPlanEstimateTotal':feature.AcceptedLeafStoryPlanEstimateTotal,
  'Feature_payload':feature._ref,
  'Created by':feature.CreatedBy.DisplayName
 }
 #print(a.keys())
 #print(a.values())
 r=r.append(a,ignore_index=True,sort=False)
 print(r)

标签: pythonapirestrallypyral

解决方案


在我看来,ID 为 44012386960 的对象已损坏,因此您必须跳过它。

for feature in features:
    if feature.oid == 44012386960:
        continue
    print(feature.details())

我假设你的错误是一个错误的特征,因为它也发生在你的第二个循环中,它只使用 feature.oid 但也有可能 feature.CreatedBy 是问题,因为你的错误消息表明它是一个错误的用户 oid。出于这种考虑,我的建议是在循环中打印 feature.CreatedBy.oid 以找到坏的并将我的 if 更改为if feature.CreatedBy.oid == 44012386960: continue


推荐阅读