Python无法读取wsdl

2024-04-28 23:14:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用此代码从wsdl获取数据。在

在网站上查询zipid(“60630”)可以正常工作,但在我的代码中,它给出的错误是

“无效ZIP”

wsdlFile = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl'
wsdlObject = WSDL.Proxy(wsdlFile)
wsdlObject.show_methods()
zipid = "60630"
result = wsdlObject.GetCityWeatherByZIP(ZIP=zipid)
print result[1]

有人能帮忙这里出了什么问题,为什么代码不能正常工作。在

谢谢!!!在


Tags: 代码comhttp网站错误resultzipwsdl
1条回答
网友
1楼 · 发布于 2024-04-28 23:14:35

问题可能是你的客户机发送了一个服务器无法理解的请求。似乎您正在使用SOAPpy,这是我尝试时它发送的请求:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<SOAP-ENV:Body>
<GetCityWeatherByZIP SOAP-ENC:root="1">
<v1 xsi:type="xsd:string">60630</v1>
</GetCityWeatherByZIP>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

在comprison中使用^{}

^{pr2}$

它产生:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://ws.cdyne.com/WeatherWS/"
    xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <ns1:Body>
    <ns0:GetCityWeatherByZIP>
      <ns0:ZIP>60630</ns0:ZIP>
    </ns0:GetCityWeatherByZIP>
  </ns1:Body>
</SOAP-ENV:Envelope>

(用wireshark捕捉)

第二个请求从服务器返回一个有效的结果。在

我对SOAPpy的了解还不足以建议解决这个问题的方法,但也许您可以考虑将您的客户端库切换到suds。在

相关问题 更多 >