python調用webservice接口(SOAP)
(1)接口是一個url,示例:http://xxx.xxx.xxx.xxx/webservice/services/SecurityEngineDeal?wsdl
(2)調用示例:
? ? ?需要先安裝suds庫:pip install suds
? ? from suds.client import Client
? ? #如果需要登錄,則通過下面方式認證(電腦的開機賬號密碼),無需登錄請忽略
? ? from suds.transport.https import HttpAuthenticated
? ? t = HttpAuthenticated(username='admin',passowrd='123')
? ? test = Client(url,t)
? ? #如果不需要登錄直接像下面這樣
? ?test = Client(url)
? ?print test? ? ? ?//會顯示所有的接口名及參數
? ?#調用具體某個接口
? ?[1]參數為普通參數類型,如string ,int
? ?????????test.service.接口名(參數)
?????? ?? ?#以接口GetRandom為例,傳遞一個類型為String的參數,參數類型在url中type="xs:string"這里會顯示
? ? ? ? ? ?print test.service.GetRandom('firstParam')? ? //傳遞一個參數,并打印調用結果
? ? ? ? ? #傳遞2個string?參數
? ? ? ? ? print test.service.GetRandom('firstParam','twoParam')
? ? ? ? ? #傳遞1個string,1個int類型
? ? ? ? ? print test.service.GetRandom('firstParam',2)
? ?[2]參數為具體的某個對象,對象包含屬性
? ? ? ? ?對象類:User,屬性:name,age,都為string
? ? ? ? ?方法一:
? ? ? ? ? ? ? m = {"name":"feng","age":"88"}
? ? ? ? ? ? ?print?test.service.GetRandom(m)
? ? ? ? 方法二:
? ? ? ? ? ? ? m = client.factory.create('User')
? ? ? ? ? ? ? m.name = "name"
? ? ? ? ? ? ? m.age = "00"
? ? ? ? ? ? ?print test.service.GetRandom(m)
2.python調用com接口
? ?本地存在一個名為XTXAppCOM.dll的文件
? ?comlib =? win32.Dispatch('XTXAppCOM.XTXApp')
? ?調用示例:
? ? ?comlib.接口名(接口參數)
3.python調用c接口
? ? ? import ctypes
? ?
? ? ? ?XTXDllBasePath = p + r'\Lib\site-packages\APIIntercommLibrary\lib\XTX\\'
? ? ? ? XTXDllPath = XTXDllBasePath + 'XTXAppCOM.dll'
? ? ? ? self.XTXC = ctypes.windll.LoadLibrary(XTXDllPath)
? ? ? ?調用示例:
? ? ? ? 注意轉換為c接口能接受的類型
? ? ? ? self.XTXC.接口名(接口參數)
4.python調用websocket
? ? ?data是根據實際情況需要傳的參數,一般為json格式,r就是得到的返回值
????from websocket import create_connection
????url = "ws://127.0.0.1:21051/xtxapp"
????ws = create_connection(url)
????ws.send(data)
????r = ws.recv()
其他接口調用方式將很快補充上。。。。。
? ?
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。