python要写一个soap客户端,应该import那些包?

zuiweiii 2012-03-28 08:59:51
包括实现soap客户端的功能,处理一个wsdl,解析xml文件这3个部分。

都需要引入哪些包? 调用soap个功能需要安装额外的python插件吗?

我用的python 2.6.4
...全文
170 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
WaistCoat05 2012-03-28
  • 打赏
  • 举报
回复
贴个CSDN的例子:
def getTopicsOfUser(loginUserName, password):
format = '''<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetTopicsOfUser xmlns="http://www.csdn.net/">
<identity>
<username>%s</username>
<password>%s</password>
</identity>
<listType>TopicOfUser</listType>
<forumId>a3049f56-b572-48f5-89be-4797b70d71cd</forumId>
</GetTopicsOfUser>
</soap12:Body>
</soap12:Envelope>'''

contentText = format % (loginUserName, password)


conn = httplib.HTTPConnection("forum.csdn.net")
headers = { "Connection":"close",
"Content-Type": "text/xml; charset=utf-8",
"SOAPAction": "http://www.csdn.net/GetTopicsOfUser"}
headers["Content-Length"] = "%d" % len(contentText)

conn.request("POST",
"/OpenApi/forumapi.asmx",
contentText,
headers)
r1 = conn.getresponse()
WaistCoat05 2012-03-28
  • 打赏
  • 举报
回复
import httplib
from xml.dom import minidom
import urllib
from urlparse import urlparse


这几个就差不多了。

soap其实就是一个POST内容是XML数据。
zuiweiii 2012-03-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

贴个CSDN的例子:
Python code
def getTopicsOfUser(loginUserName, password):
format = '''<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xm……
[/Quote]

我把你上面给的两段代码合并到了一起,查询我自己在csdn里面的发帖,运行了一下,抛错:

>>>
Traceback (most recent call last):
File "D:\csdn.py", line 36, in <module>
getTopicsOfUser('zuiweiii','lkjfdsa')
File "D:\csdn.py", line 33, in getTopicsOfUser
headers)
File "C:\Python26\lib\httplib.py", line 898, in request
self._send_request(method, url, body, headers)
File "C:\Python26\lib\httplib.py", line 935, in _send_request
self.endheaders()
File "C:\Python26\lib\httplib.py", line 892, in endheaders
self._send_output()
File "C:\Python26\lib\httplib.py", line 764, in _send_output
self.send(msg)
File "C:\Python26\lib\httplib.py", line 723, in send
self.connect()
File "C:\Python26\lib\httplib.py", line 704, in connect
self.timeout)
File "C:\Python26\lib\socket.py", line 514, in create_connection
raise error, msg
error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

37,741

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧