博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python开发之扩展库的安装指南及Suds(Webservice)的使用简介
阅读量:4046 次
发布时间:2019-05-24

本文共 1915 字,大约阅读时间需要 6 分钟。

昨天想用python去调用一个公司提供的webservice功能,结果发现python现在有的webservice功能都是第三方扩展库,官方竟然没有提供,经历了多次磨难后,总算知道如何去用python实现一个webservice了,下面是一些总结

我的博客:

1.关于第三方扩展库的安装
首先建议你安装一个扩展库安装工具,推荐easy_install工具,你可以在网上下载,也可以先去下载一个 ez_setup.py ,这个程序下载后用python.exe运行一下,会自动根据你的版本帮你下载和安装一个easy_install,目前只支持到python2.6,看来python3目前还是没有太多的公司在使用啊。。。
后面就可以用这个easy_install工具进行第三方库的下载了,比如我要下载soaplib这个库,可以执行easy_install soaplib,它会自己去相关网站查找这个库,以及这个库的依赖,如果你手工安装,那依赖会把你搞疯掉的(我就被折腾了1天多)
2.关于哪个库更适用做webservice
现在网上查到最多的是ZSI或者叫soappy,实际上05年之后就没有更新了,而且只支持到2.5,放弃
soaplib,这个目前2.0,还是不错的,不过手册不是太好读,只有server端的用法,client我没找到

suds,这个我在用,用起来比较简单,示例代码如下:

The library is now ready to use. We start by importing the suds library, creating a client based on a SOAP url, and asking the library to print the SOAP web service methods that are available to us.import sudsurl = "http://www.ecubicle.net/iptocountry.asmx?wsdl"client = suds.client.Client(url)print clientFrom the output of the last print command, we learn that there is a method called FindCountryAsString that takes one argument: the IP address.print client.service.FindCountryAsString("194.145.200.104")And it shows (edited for readability):
Netherlands
Normally you want to have the contents of the SOAP body. This is what suds provides in a very elegant way. However, you’re a bit stuck when you want to get something from the SOAP header. The author of suds realised this and made a backdoor to get the information anyway. We start by showing what the function last_received contains:print client.last_received()
1000
Success
...
We can get portions of this data by doing some XML handling. Let’s say we want to print the resultCode:print client.last_received().getChild("soap:Envelope").getChild("soap:Header").getChild("ResponseHeader").getChild("resultCode").getText()

转载地址:http://wwwci.baihongyu.com/

你可能感兴趣的文章
mongodb mongoexprt 导出数据 json csv格式
查看>>
MySQL MERGE存储引擎 简
查看>>
数据库分片(Sharding)与分区(Partition)的区别
查看>>
node.js递归打印文件目录、文件名
查看>>
本地与远程linux上传下载
查看>>
NodeJS的代码调试和性能调优
查看>>
浅谈V8引擎中的垃圾回收机制
查看>>
引擎V8及优化技术
查看>>
Node.js domain异常捕获的一些实践
查看>>
mac下修改环境变量
查看>>
JVM性能调优
查看>>
JVM调优总结
查看>>
Redis与Memcached的区别
查看>>
WebSocket(1)-- WebSocket API简介
查看>>
WebSocket(2)--为什么引入WebSocket协议
查看>>
WebSocket(3)-- WebSocket协议简介
查看>>
WebSocket(4)-- WebSocket与TCP、Http的关系
查看>>
TCP/IP, WebSocket 和 MQTT
查看>>
CentOS、Ubuntu、Debian三个linux比较异同
查看>>
javascript闭包和闭包的几种写法及用途
查看>>