Python calls WebService interface using SUDS

Source: Internet
Author: User
Tags wsdl

Recently done interface docking, encountered the. NET development of the WebService interface, because Python for the first time with the WebService docking, even ask for a check, and finally use the SUDS library to achieve

1. Installing Suds

Mac:sudo Pip Install Suds

Linux:easy_install Suds

You can also download the Suds code by going to the official website and install it locally.

2. Reference initialization

1>>>From suds.client Import client2>>> URL ='http://www.gpsso.com/webservice/kuaidi/kuaidi.asmx?wsdl'3>>> client =Client (URL)4>>>Print Client5 6Suds (https://fedorahosted.org/suds/) version:0.4 GA build:r699-201009137 8Service (Kuaidi) tns="http://gpsso.com/"9Prefixes (1)TenNS0 ="http://gpsso.com/" OnePorts (2): A (KUAIDISOAP) -Methods (1): -Kuaidiquery (xs:stringCompay, xs:stringOrderNo,) theTypes (1): - Apisoapheader - (KUAIDISOAP12) -Methods (1): +Kuaidiquery (xs:stringCompay, xs:stringOrderNo,) -Types (1): + Apisoapheader A>>>

To make a description of the URL, it is generally to confirm that the WSDL address is normal mode, the address opening is generally in XML format and some services are made into HTML mode, which will lead to instantiation or call method when the XML parsing exception.

3. Method invocation

2 of the client print out to know, the Webserviece service defines what method, the method needs what parameters, what information is declared, such as header information, Apisoapheader, method can be called directly through Client.serviece

>>> client.service.KuaidiQuery (company='EMS', orderno='1111  ') (kuaidiqueryresult) {   =      (API) {         "0"          "interface query succeeded"}} >>>          

While the header information is declared, it can be instantiated in a factory way

>>> Header = Client.factory.create ('Apisoapheader')>>>Print Header (apisoapheader) {Apicode=None APIKey=None}>>> header. Apicode ='123'>>> header. APIKey ='key123'>>>Print Header (apisoapheader) {Apicode="123"APIKey="key123" }>>>

Header information needs to be set with the Set_options method

>>>>>> client.set_options (soapheaders=[Header,])>>>

If there is no header information described, you can set the Https://fedorahosted.org/suds/wiki/Documentation query custom SOAP headers by reviewing the document.

4. Attach a reference to your friend's article http://www.cnblogs.com/Tommy-Yu/p/5567091.html

Reprint please indicate the source of this article: http://www.cnblogs.com/nottobe/p/5718823.html

Thank you

Python calls the WebService interface using SUDS

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.