2014-06-20 15 views
1

我試圖從soap定義的webservice中使用方法。我能夠連接並獲取有關方法的信息,但是當我嘗試使用方法,然後我得到錯誤說泡沫(SOAP) - 服務器引發的錯誤 - 未指定參數'用戶名'

Server raised fault: 'Unspecified parameter 'username''

所以我客串的時候我想將數據發送到服務器,由於某種原因,嘗試發送沒有用戶名? 我試圖連接(驗證)到web服務在泡沫文檔中描述的各種方法:https://fedorahosted.org/suds/wiki/Documentation

兩種方法都給出了上述錯誤。

比如我這樣寫的:

# -*- encoding: utf-8 -*- 
import logging 
from suds.client import Client 
from suds import WebFault 
#from suds.transport.https import WindowsHttpAuthenticated 
from suds.transport.http import HttpAuthenticated 
logging.basicConfig(level=logging.INFO) 
logging.getLogger('suds.client').setLevel(logging.DEBUG) 

url = 'some_url?wsdl' 
t = HttpAuthenticated() 
client = Client(url, transport=t, username='username', password='password') 
#print client 
card = client.factory.create('Type1') 
cs = card.subtype 
cs.param1 = 25 
cs.param2 = 26 
cs.param3 = '1234567891' 



try: 
    card_created = client.service.method1(card) 
except WebFault, e: 
    print e 

與信封整體錯誤是這樣的:

DEBUG:suds.client:http failed: 
<?xml version='1.0' encoding='UTF-8'?><S:Envelope 
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><S:Fault  
xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"><faultcode>S:Server</faultcode> 
<faultstring>Unspecified parameter 'username'</faultstring><detail><ns2:Exception 
xmlns:ns2="http://some_other_url/"><message>Unspecified parameter 

'用戶名' 服務器提出故障: '未指定的參數 '用戶名''

我也試過從類似問題的解決方案在這裏: http://blogs.it.ox.ac.uk/inapickle/2011/05/14/exchange-web-services-suds-and-python/ 但我沒有幫助。 更新 - 我也嘗試了一些泡沫叉,但仍然是同樣的問題(具體 - suds-jurkosuds-ews)。

我該如何通過指定驗證來強制使用方法(以及其他細節,如果它以後可能會丟失)?

UPDATE2 當我改變了這樣的身份認證實施方案(其實非常類似的方法,我張貼以上):

from suds.transport.http import HttpAuthenticated 
t = HttpAuthenticated(username='username', password='password') 
client = Client(url, transport=t) 

,然後當我嘗試使用方法(同我上面寫的),我得到這個錯誤:

<i>Hypertext Transfer Protocol -- HTTP/1.1</i>:</H3> 
    </FONT><FONT FACE="Helvetica" SIZE="3"><H4>10.4.2 401 Unauthorized</H4> 
    </FONT><P><FONT FACE="Courier New">The request requires user authentication. The 
response MUST include a WWW-Authenticate header field (section 14.46) containing a 
challenge applicable to the requested resource. The client MAY repeat the request with a 
suitable Authorization header field (section 14.8). If the request already included 
Authorization credentials, then the 401 response indicates that authorization has been 
refused for those credentials. If the 401 response contains the same challenge as the 
prior response, and the user agent has already attempted authentication at least once, 
then the user SHOULD be presented the entity that was given in the response, since that 
entity MAY include relevant diagnostic information. HTTP access authentication is 
explained in section 11.</FONT></P> 

所以我覺得跟以前的方法服務器未看到用戶名,但現在由於某種原因,它只是拒絕授權?它會是這樣的嗎?

回答

1

終於找到了解決辦法。當我指定的用戶名/密碼頭「手動」我只能驗證這樣的:

client = Client(url, headers = {'username': 'username', 'password': 'password'}) 

理念從JK1答案How to add http headers in suds 0.3.6?

來到