Я хочу прочитать тег из XML-ответа, в котором много пространства имен.раньше он работал, но теперь перестал работать: (
код:
следующий код работал раньше, но теперь не работает
response = requests.post(url,data=body,headers=Headers)
tree = ET.fromstring(response.content)
lst = tree.find('.//Id').text
print('request submitted Request Id: '+str(lst))
Error:
Traceback (most recent call last):
File "p3.py", line 179, in <module>
lst = tree.find('.//Id').text
AttributeError: 'NoneType' object has no attribute 'text'
Я пытался подписаться, но неработая большую часть времени, он возвращает [] or None
.
st=(response.content)
st1=(st.decode('utf-8'))
root=ET.fromstring(st1)
ID =root.findall("./findContractResponse/")
#root=tree.getroot()
#print(root.tag)
#print(root.attrib)
# xmlstr is your xml in a string
#root = lxml.etree.fromstring(st1)
#textelem = root.find('Body/findContractResponse/result/Value/Id')
#print (textelem.text)
namespaces = {'ns1': 'http://xmlns.oracle.com/apps/contracts/coreAuthoring/contractService/'}
ns1="http://xmlns.oracle.com/apps/contracts/coreAuthoring/contractService/"
#root = ET.fromstring(xml)
print(root.findall('ns1:Value', namespaces))
#str=root.findall('ns1:Value', namespaces)
#print(str)
print(root.find('{http://xmlns.oracle.com/apps/contracts/coreAuthoring/contractService/}Value'))
Ниже приведен XML-ответ, который я получаю от запросов SOAP
xml ="""<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:typ="http://xmlns.oracle.com/apps/contracts/coreAuthoring/contractService/types/">
<env:Header>
<wsa:Action>http://xmlns.oracle.com/apps/contracts/coreAuthoring/contractService//ContractService/findContractResponse</wsa:Action>
<wsa:MessageID>urn:uuid:12310951-51ba-4f8c-af28-71f22f65ed64</wsa:MessageID>
<wsse:Security env:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp wsu:Id="Timestamp-1sBNCU5ovGHx3N8YmAzKIQ22" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>2018-12-12T06:53:00Z</wsu:Created>
<wsu:Expires>2018-12-15T18:13:00Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</env:Header>
<env:Body>
<ns0:findContractResponse xmlns:ns0="http://xmlns.oracle.com/apps/contracts/coreAuthoring/contractService/types/">
<ns2:result xsi:type="ns1:ContractHeaderResult" xmlns:ns2="http://xmlns.oracle.com/apps/contracts/coreAuthoring/contractService/types/" xmlns:ns1="http://xmlns.oracle.com/apps/contracts/coreAuthoring/contractService/" xmlns:tns="http://xmlns.oracle.com/adf/svc/errors/" xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/" xmlns:ns5="http://xmlns.oracle.com/apps/projects/billing/contracts/contractPublicService/" xmlns:ns6="http://xmlns.oracle.com/apps/projects/billing/contracts/contractBillingService/" xmlns:ns7="http://xmlns.oracle.com/apps/contracts/coreAuthoring/header/flex/header/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:Value>
<ns1:Id>100000011169350</ns1:Id>
</ns1:Value>
<ns1:Value>
<ns1:Id>100000011169350</ns1:Id>
</ns1:Value>
</ns2:result>
</ns0:findContractResponse>
</env:Body>
</env:Envelope>"""
Ребята, я застрял здесь, я пытался использовать elementreeвсе варианты, но помнить, помогает. Ирония в том, что он работал раньше, но я не знаю, почему он не работает сейчас