1

我正在尝试阅读此 Soap API http://telemetriaws1.ana.gov.br/ServiceANA.asmx?WSDL。当我尝试调用DadosHidrometeorologicosGerais函数时,出现此错误:

File "/home/1234/.local/share/virtualenvs/data_getter-1W9NAele/lib/python3.6/site-packages/zeep/xsd/schema.py", line 570, in _get_component
return items[qname]
KeyError: <lxml.etree.QName object at 0x7f2e93fa6d00>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
zeep.exceptions.LookupError: No element 'DocumentElement' in namespace None. Available elements are: NewDataSet

所有其他功能工作正常。

这是我的代码:

 from zeep import Client

 client = Client('http://telemetriaws1.ana.gov.br/ServiceANA.asmx?WSDL')
 client.service.DadosHidrometeorologicosGerais(codEstacao='86450500', dataInicio='05/05/2018', dataFim='05/05/2018')
4

1 回答 1

0

我不确定,但 xml 文件似乎是从某些数据集生成的。“id”属性与元素的标识不匹配。

一种可能的解决方案是省略对 XML 的 zeep 解析并返回原始数据。使用模块xml.etree.ElementTree来解析它。

from zeep import Client, Settings
import xml.etree.ElementTree as ET

settings = Settings(force_https=False, raw_response=True)
WSDL = 'http://telemetriaws1.ana.gov.br/ServiceANA.asmx?WSDL'

client = Client(WSDL, settings=settings)

response = client.service.DadosHidrometeorologicosGerais(codEstacao='86450500',
                                                     dataInicio='05/05/2018',
                                                     dataFim='05/05/2018')

root = ET.fromstring(response.content)
于 2018-11-09T00:01:57.960 回答