您的位置:首页 > 编程语言 > Python开发

Python实现文件上传下载的SOAP Client

2009-08-03 22:10 661 查看
suds是Python的一个soap库。下载suds。把文件拷入python的库目录下。

soapclient.py
from suds.client import Client
from suds.sax.element import Element
import base64

def upFile(client,file):
f = open(file,'rb')
fs = f.read()

attach = client.factory.create('ns0:Base64Attachment') # 'ns0:Base64Attachment'为wsdl中定义的类型
attach.base64FileStr = base64.encodestring(fs)
attach.attName='test'
r = client.service.upFile(attach)

def downFile(client,fileID):
r = client.service.downFile(fileID)

if __name__=="__main__":
url='http://localhost/services/FileUpAndDownService?wsdl'
client = Client(url)

# set soap header
u = Element('Username')
u.setText('user')
p = Element('Password')
p.setText('password')
client.set_options(soapheaders=(u,p))

upFile(client,r"c:\test")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: