2013-02-12 80 views
0

我正在嘗試使用pysimplesoap與Websitepanel SOAP-API進行通信。 WebsitePanel API簡介說:正確使用pysimplesoap進行身份驗證的問題

對於與WebsitePanel API進行交互,您應該使用基本身份驗證。 WebsitePanel承認在以下格式提供的用戶憑據「授權」標頭:用戶名:密碼

我第一次嘗試了以下內容:

client = SoapClient(wsdl=endpoint_url, trace=True) 
client['Authorization'] = "%s:%s" % (username, password) 

它返回一個401「未授權」。 第二個嘗試是:

client = SoapClient(wsdl=endpoint_url, trace=True)   
client['wsse:Security'] = { 
    'wsse:UsernameToken': { 
     'wsse:Username': username, 
     'wsse:Password': password, 
    } 
}  

其工作正常,但返回以下內容:

status: 500 
content-length: 924 
x-aspnet-version: 4.0.30319 
x-powered-by: ASP.NET 
server: Microsoft-IIS/7.5 
cache-control: private 
date: Tue, 12 Feb 2013 14:23:56 GMT 
content-type: text/xml; charset=utf-8 

而且

pysimplesoap.client.SoapFault: q0:Security: SOAP response should be signed. 

爲什麼client['Authorization']沒有工作,什麼是由Response should be signed錯誤信息的意思?

在此先感謝。

回答

3

我想通了:要使用pysimplesoap正確驗證你必須調用

client = SoapClient(wsdl=u, trace=True, 
        http_headers={'Authorization': 'Basic %s' % encoded}) 

encoded beeing base64編碼字符串username:password

+0

我想這一點,但SoapClient的的初始化程序不接受該關鍵字參數'http_headers'。此代碼示例是否正確? – 2013-06-13 20:56:54

+0

我正在使用版本1.07a - 它工作正常。 SoapClient初始化程序的實際簽名是:'def __init __(self,location = None,action = None,namespace = None, cert = None,trace = False,exceptions = True,proxy = None,ns = False, soap_ns = None,wsdl = None,cache = False,cacert = None, sessions = False,soap_server = None,timeout = _USE_GLOBAL_DEFAULT, http_headers = {} ) – Subito 2013-06-26 10:04:11