SOAPPY Call Weather Forecast WebService

SOAPpy is a very old library, the most recent maintenance is 6 years ago; I heard about this library somehow, I want to use this library to start learning WebService, and finally proved to be a pit .

This afternoon I finally climbed the pit successfully (that is, climbed a few basic pits).

The first pit is, after installation, I can’t even run:

TypeError: callInfoFromWSDL() takes exactly 3 arguments (2 given)

p>

Go and modify the WSDL.py file, line 97, and use self as the first parameter of callInfoFromWSDL.

Then imitate this blogger’s article: http://blog.csdn.net/shuxiaomeng/article/details/6531077 to try to call the weather forecast service: it runs successfully, but the blogger A getSupportProvice method is transferred, which can output the supported province name. Then I tried other interfaces and found that all interfaces that need to pass parameters failed. (No wonder the blogger only implemented one example…) By looking at various documents, including official and online forums. Finally, I released an upgraded version of SoapUI, ReadAPI, and used it to do SOAP request sending and receiving experiments. The problem I located: Namespace. To solve this problem, two steps are required: The first step is to add a namespace to the method, and after adding it, it is found that the parameter still has no namespace. So I found through foreign forums that I wanted to modify the SOAPBuilder.py text and modify the tag settings in it.

  • The method of adding a name space to a method, such as: server.methods["getSupportCity"].namespace=("tns","http://WebXml.com.cn/" )
  • Modify tag settings:
tag = tag or self.gentag()
if self.namespace:
tag = self.namespace[0] + ":" + tag
#tag = ns_map.get(self.namespace) + ":" + tag
tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

My modification is a bit different from what the gringo said, in that for the namespace where the name is explicitly given, the tag will be a tuple, so that None will be returned when calling ns_map.get. In short, everyone remember to modify the tag in this place to look what we want, so that the method parameters and so on will have a namespace. The final results are shown below:

#encoding=utf-8
from SOAPpy import WSDL,SOAPProxy




wsdlFile ='http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl'

server = WSDL.Proxy(wsdlFile)

# The following two Line is used to output debugging information
server.soapproxy.config.dumpSOAPOut=1
#server.soapproxy.config.dumpSOAPIn = 1

#server.methods["getSupportProvince"] .namespace=("sdfsd","http://www.baidu.com")
print server.methods

#Get a supported identity
for a in server. getSupportProvince():
for i in a:
print i

print "*"*30
server.methods["getSupportCity"].namespace=(" tns","http://WebXml.com.cn/")

#Get the city of the province
for a in server.getSupportCity(byProvinceName=u"Hubei"):
for i in a:print i

#Get weather forecast
server.methods["getWeatherbyCityName"].namespace=("tns","http://WebXml.com. cn/")

for a in server.getWeatherbyCityName(theCityName=u"Wuhan"):
for i in a:print i

Part of the output is as follows

p>

** ************************************************** ********************
Hubei
Wuhan
57494
57494.jpg
2017-10- 20 15:50:54
11℃/21℃
October 20 is cloudy
No continuous wind direction and breeze
1.gif
1.gif
Today’s weather conditions: temperature: 20℃; wind direction/wind: northeast wind level 3; humidity: 55%; UV intensity: weak. Air quality: medium.
Ultraviolet index: weak, weak radiation, rub SPF12-15, PA+ skin care products.
Cold index: It is easy to get cold, and the temperature difference is big in cool weather, so increase or decrease clothes appropriately.
Clothing index: more comfortable, it is recommended to wear a thin coat or jeans and other clothing.
Car wash index: more suitable, no rain and low wind, easy to maintain cleanliness.
Sports index: suitable, good weather, enjoy the joy of sports.
Air Pollution Index: Medium and susceptible people should appropriately reduce outdoor activities.

11℃/22℃
October 21st, sunny
No continuous wind direction, breeze
0.gif
0.gif
13℃ /23℃
It was cloudy to overcast on October 22
No continuous wind direction and breeze
1.gif
2.gif
Wuhan city is located in the east of Jianghan Plain, the middle reaches of the Yangtze River and The confluence of the Yangtze River and Hanshui River. East longitude 113°41'-115°05', north latitude 29°58'-31°22'. Wuhan City has an advantageous geographical location. The Yangtze River and its largest tributary Han River converge here. Wuhan City is naturally divided into three towns, Hankou, Hanyang and Wuchang. Wuhan is a water and land transportation hub in my country. Known as "the thoroughfare of nine provinces", the city's freight throughput is now more than 100 million tons. The superior geographical location has become a strategic place for warriors in the past. During the Three Kingdoms period, Wuhan's East Lake was once a place where Liu Bei, Sun Quan, and Cao Cao conducted military and political activities. Now there are ancient buildings such as Liu Bei’s Jiao Tiantai, Wuwang Temple, Cao Cao Temple, and Hongshan Pagoda. Wuhan has now developed into a center of industry, finance, commerce, science, culture and education in central China. Wuhan has a subtropical humid monsoon climate, with abundant rainfall, abundant sunshine and four distinct seasons. The overall climate is good. In the past 30 years, the average annual rainfall was 1269 mm, mostly in June-August. The annual average temperature is 15.8℃-17.5℃, the annual frost-free period is generally 211 days to 272 days, and the total annual sunshine hours are 1810 hours to 2100 hours. Landscape: Wudang Mountain, Three Gorges of Yangtze River, Shennongjia, etc.

Summary: Although there are many Chinese people and the forums are lively, they are not rigorous and often fail to find the source of the problem. Finally, it depends on what is said on foreign forums.

The lesson this time is that with regard to the stuff of network protocols, you must find an emulator so that you can locate the problem.

If you want to learn WebService together, please contact and exchange ideas.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3474 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.