python調用各種接口,webservice,c接口,com接口,socket協議方法

  1. python調用webservice接口

    (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)


其他接口調用方式將很快補充上。。。。。


   

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章