python調用suds方法,suds Python

本文目錄一覽:

怎麼安裝python 的擴展庫-suds?

首先建議你安裝一個擴展庫安裝工具,推薦easy_install工具,你可以在網上下載,也可以先去下載一個 ez_setup.py ,這個程序下載後用python.exe運行一下,會自動根據你的版本幫你下載和安裝一個easy_install,目前只支持到python2.6,看來python3目前還是沒有太多的公司在使用啊。。。

後面就可以用這個easy_install工具進行第三方庫的下載了,比如我要下載soaplib這個庫,可以執行easy_install soaplib,它會自己去相關網站查找這個庫,以及這個庫的依賴,如果你手工安裝,那依賴會把你搞瘋掉的

關於哪個庫更適用做webservice

現在網上查到最多的是ZSI或者叫soappy,實際上05年之後就沒有更新了,而且只支持到2.5,放棄

soaplib,這個目前2.0,還是不錯的,不過手冊不是太好讀,只有server端的用法,client我沒找到suds,這個我在用,用起來比較簡單,示例代碼如下:

[python] view plain copy

The library is now ready to use. We start by importing the suds library, creating a client based on a SOAP url, and asking the library to print the SOAP web service methods that are available to us.

import suds

url = “”

client = suds.client.Client(url)

print client

From the output of the last print command, we learn that there is a method called FindCountryAsString that takes one argument: the IP address.

print client.service.FindCountryAsString(“194.145.200.104”)

And it shows (edited for readability):

?xml version=”1.0″?

IPAddressService

countryNetherlands/country

/IPAddressService

Normally you want to have the contents of the SOAP body. This is what suds provides in a very elegant way. However, you』re a bit stuck when you want to get something from the SOAP header. The author of suds realised this and made a backdoor to get the information anyway. We start by showing what the function last_received contains:

print client.last_received()

?xml version=”1.0″ encoding=”UTF-8″?

soap:Envelope

soap:Header

ResponseHeader xmlns=””

resultCode1000/resultCode

resultDescriptionSuccess/resultDescription

/ResponseHeader

/soap:Header

soap:Body

/soap:Body

/soap:Envelope

We can get portions of this data by doing some XML handling. Let』s say we want to print the resultCode:

print client.last_received().getChild(“soap:Envelope”).getChild(“soap:Header”)

.getChild(“ResponseHeader”).getChild(“resultCode”).getText()

python調用suds方法,拋出”對象實例沒有設置”的異常,為什麼

public MappingMongoConverter mongoConverter() throws UnknownHostException {

MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory(), mongoMappingContext());

converter.setTypeMapper(mongoTypeMapper());

return converter;

}

python用suds 調用webservice方法的時候報錯。

其實用Python進行webservice通信進行數據交換,就是拼接字元串,沒必要用第三方的庫。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/193763.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-02 09:40
下一篇 2024-12-02 09:40

相關推薦

  • Python周杰倫代碼用法介紹

    本文將從多個方面對Python周杰倫代碼進行詳細的闡述。 一、代碼介紹 from urllib.request import urlopen from bs4 import Bea…

    編程 2025-04-29
  • Python中引入上一級目錄中函數

    Python中經常需要調用其他文件夾中的模塊或函數,其中一個常見的操作是引入上一級目錄中的函數。在此,我們將從多個角度詳細解釋如何在Python中引入上一級目錄的函數。 一、加入環…

    編程 2025-04-29
  • Python計算陽曆日期對應周幾

    本文介紹如何通過Python計算任意陽曆日期對應周幾。 一、獲取日期 獲取日期可以通過Python內置的模塊datetime實現,示例代碼如下: from datetime imp…

    編程 2025-04-29
  • 如何查看Anaconda中Python路徑

    對Anaconda中Python路徑即conda環境的查看進行詳細的闡述。 一、使用命令行查看 1、在Windows系統中,可以使用命令提示符(cmd)或者Anaconda Pro…

    編程 2025-04-29
  • Python列表中負數的個數

    Python列表是一個有序的集合,可以存儲多個不同類型的元素。而負數是指小於0的整數。在Python列表中,我們想要找到負數的個數,可以通過以下幾個方面進行實現。 一、使用循環遍歷…

    編程 2025-04-29
  • Python程序需要編譯才能執行

    Python 被廣泛應用於數據分析、人工智慧、科學計算等領域,它的靈活性和簡單易學的性質使得越來越多的人喜歡使用 Python 進行編程。然而,在 Python 中程序執行的方式不…

    編程 2025-04-29
  • Python字典去重複工具

    使用Python語言編寫字典去重複工具,可幫助用戶快速去重複。 一、字典去重複工具的需求 在使用Python編寫程序時,我們經常需要處理數據文件,其中包含了大量的重複數據。為了方便…

    編程 2025-04-29
  • python強行終止程序快捷鍵

    本文將從多個方面對python強行終止程序快捷鍵進行詳細闡述,並提供相應代碼示例。 一、Ctrl+C快捷鍵 Ctrl+C快捷鍵是在終端中經常用來強行終止運行的程序。當你在終端中運行…

    編程 2025-04-29
  • 蝴蝶優化演算法Python版

    蝴蝶優化演算法是一種基於仿生學的優化演算法,模仿自然界中的蝴蝶進行搜索。它可以應用於多個領域的優化問題,包括數學優化、工程問題、機器學習等。本文將從多個方面對蝴蝶優化演算法Python版…

    編程 2025-04-29
  • Python清華鏡像下載

    Python清華鏡像是一個高質量的Python開發資源鏡像站,提供了Python及其相關的開發工具、框架和文檔的下載服務。本文將從以下幾個方面對Python清華鏡像下載進行詳細的闡…

    編程 2025-04-29

發表回復

登錄後才能評論