Python uses suds to invoke webservice

Source: Internet
Author: User

For Python to invoke WebService only as a client, it is recommended to use the Suds library, which is quite lightweight and easy to use compared to zsi,soapy.

Installation suds is recommended for use with Easy_insall. Here are some of the official examples:

  Python code    from suds.client import client   url =  ' http:// Localhost:7080/webservices/webservicetestbean?wsdl '    client = client (URL)       #查看该service提供的方法    print client      suds - version:  0.3.3 build:  (Beta)  R397-20081121      service  ( Webservicetestbeanservice)  tns= "http://test.server.enterprise.rhq.org/"        prefixes  (1):        ns0 =  "http:// test.server.enterprise.rhq.org/"      Ports  (1):          (Soap)           Methods:             addperson (person person, )              echo (xs:string arg0, )             getlist (xs:string str, xs: int length, )             getpercentbodyfat (xs: String name, xs:int height, xs:int weight)              getpersonbyname (name name, )              hello ()             testexceptions ()             testlistarg (xs:string[] list, )             testvoid ()              updateperson (anotherperson person, name name, )        Types  (:        Person    )     name        Phone         anotherperson  

1. Simple parameter call

Python code result = Client.service.getPercentBodyFat (' Jeff ', 170) Print result = Client.service.getPerc Entbodyfat (name= ' Jeff ', height=68, weight=170) print result #词典 D = dict (name= ' Jeff ', height=68, weight=170) re Sult = Client.service.getPercentBodyFat (**d) print result for you have 21% body fat.

2. Complex parameters

Java Code person = client.factory.create ("person") print person

  Java code    (person) =     {       phone =  []       age = NONE       name (name)  =            {                last = NONE                first = NONE            }      }  

#设置变量 java Code phone = client.factory.create (' phone ') Phone.npa = Phone.nxx = 555 Phone.number = 1212 Pytho N Code name = client.factory.create (' name ') Name.first = ' Elmer ' name.last = ' Fudd '

Python code person.name = Name Person.age = km PERSON.PHONE = [Phone]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.