码迷,mamicode.com
首页 > 编程语言 > 详细

python读取webservice

时间:2016-10-14 13:48:52      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

网上最多的是suds模块,这里也使用suds。

1、安装:

  和所有python模块安装一样,可以使用easy_install或pip在线安装,也可以下载离线安装.

  https://pypi.python.org/pypi/suds/

2、简单入门:

  

import logging
from suds.client import Client   
from suds.xsd.doctor import ImportDoctor,Import
#日志,suds下的各个python模块或者说python文件大多都使用了logging模块进行日志记录,我们只需要设置好日志的等级、格式、路径等,就可以进行对应模块的日志记录了

 logging.basicConfig(level=logging.INFO,  

                    format=‘%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s‘,  

                    datefmt=‘%a, %d %b %Y %H:%M:%S‘,  

                    filename=‘/tmp/test.log‘,  

                    filemode=‘w‘) 

logging.getLogger(suds.xsd.schema).setLevel(logging.DEBUG)
#Import和DoctorImport是提供wsdl中缺少的import标签的
imp = Import("http://www.w3.org/2001/XMLSchema",location="http://www.w3.org/2001/XMLSchema.xsd")
imp.filter.add("http://WebXml.com.cn/")
doctor=ImportDoctor(imp)
url =http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx?wsdl
client = Client(url,doctor=doctor)
r = client.service.getStationName()

3、WSDL

  wsdl使用xml文件格式,xsd规范对外提供webservice接口。suds模块很大一部分是对于wsdl对应的xml文件的解析。所以需要对wsdl有个系统的了解。

  http://www.phpstudy.net/e/wsdl/

python读取webservice

标签:

原文地址:http://www.cnblogs.com/z964166725/p/5959848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!