Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python对象中出现意外的属性错误_Python_Xml_Python 2.7_Suds - Fatal编程技术网

python对象中出现意外的属性错误

python对象中出现意外的属性错误,python,xml,python-2.7,suds,Python,Xml,Python 2.7,Suds,我正在解析suds客户端从Web服务SOAP API返回的对象 <attributeValueId/> 我有一个属性对象列表,比如 (defectStateAttributeValueDataObj){ attributeDefinitionId = (attributeDefinitionIdDataObj){ name = "Comment" } attributeValueId = (attributeVa

我正在解析suds客户端从Web服务SOAP API返回的对象

<attributeValueId/>
我有一个属性对象列表,比如

(defectStateAttributeValueDataObj){
   attributeDefinitionId = 
      (attributeDefinitionIdDataObj){
         name = "Comment"
      }
   attributeValueId = 
      (attributeValueIdDataObj){
         name = "Owner changed because of default owner assignment specified in the component map"
      }
}
<attributeValueId/>

<attributeValueId/>
我使用以下循环提取键/值对:

for defect in myDefectsPage.mergedDefects :
   print defect.cid,
   for attribute in defect.defectStateAttributeValues:
       print attribute
       attr= attribute.attributeDefinitionId.name
       val=attribute.attributeValueId.name
       print attr,'=',val,
       print ""     
<attributeValueId/>
以上对象是“打印属性”命令的结果

<attributeValueId/>
除了attribute.attributeDefinitionId.name==Comment的属性外,这将对每个属性起到预期的作用

<attributeValueId/>
对于这一个,我得到了

<attributeValueId/>
回溯最近一次呼叫上次: 文件,第63行,在 val=attribute.attributeValueId.name AttributeError:“文本”对象没有属性“名称”

<attributeValueId/>
这很奇怪,因为如果我使用 val=attribute.attributeValueId.name 它会打印出来

<attributeValueId/>
COMMENT=attributeValueIdDataObj{ name=由于组件映射中指定的默认所有者分配,所有者已更改 }

<attributeValueId/>
所以它看起来像是一个attributeValueIdDataObj并且有一个name属性

<attributeValueId/>
无论attribute.attributeDefinitionId.name是什么,我都使用了suds调试日志记录,XML返回元素看起来完全相同

<attributeValueId/>
我不知道在尝试访问name属性时它是如何变成“Text”对象的

<attributeValueId/>

有什么想法吗?

在进一步检查并打印出异常发生时返回的对象的类型时,这是web服务SOAP服务器中的一个错误

<attributeValueId/>
当注释为空时,它返回一个

<attributeValueId/>
标签

<attributeValueId/>
而不是适当的

<attributeValueId/>
 <attributeValueId>
      <name/>
 </attributeValueId>
反对。因此它产生了sax.Text对象,而不是suds.attributeValueIdDataObj对象

<attributeValueId/>
因此,没有python或肥皂水之谜需要解决

<attributeValueId/>

很抱歉出现错误警报…

解决方法:valueId=attribute.attributeValueId如果hasattrvalueId,“name”:val=valueId.name其他:val=valueId有效,它表明它确实是attributeValueIdDataObj,并且它确实具有name属性,just hasattr处理AttributeError异常,而getattr或.name不处理。奇怪的
<attributeValueId/>