2012-01-02 21 views
5

私はSUDSを使用しようとしており、なぜ認証(つまりhttps)を取得できないのか把握しようとしています。Python SUDS httpsサービス401へのSOAPリクエスト

私がアクセスしようとしているサービスは、基本ダイジェスト認証のhttpsを超えています。デバッグに基づいて、httpsではなくhttpを使用しているようです。しかし、私が紛失しているものは本当にわからない。どんな手がかりもありがとう。

from suds.client import Client 
from suds.transport.http import HttpAuthenticated 
import logging 
logging.basicConfig(level=logging.DEBUG) 
logging.getLogger('suds.client').setLevel(logging.DEBUG) 
logging.getLogger('suds.transport').setLevel(logging.DEBUG) 
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG) 
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG) 

def main(): 
    url = 'https://blah.com/soap/sp/Services?wsdl' 
    credentials = dict(username='xxxx', password='xxxx') 
    t = HttpAuthenticated(**credentials) 
    client = Client(url, location='https://blah.com/soap/sp/Services', transport=t) 
    print client.last_sent() 

if __name__=="__main__": 
    main() 

デバッグ出力:

DEBUG:suds.wsdl:reading wsdl at: https://blah.com/soap/sp/Services?wsdl ... DEBUG:suds.transport.http:opening (https://blah.com/soap/sp/Services?wsdl)
snip ...
File "C:\Python27\Lib\site-packages\suds-0.4-py2.7\suds\reader.py", line 95, in download
fp = self.options.transport.open(Request(url))

File "C:\Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py", line 173, in open
return HttpTransport.open(self, request)

File "C:\Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py", line 64, in open
raise TransportError(str(e), e.code, e.fp)

suds.transport.TransportError: HTTP Error 401: Authorization Required

+0

正しさのために最初に...それだけではない「認証ダイジェスト」であるべきである「基本的なダイジェスト認証を。」 authのタイプは 'digest'と 'basic'です。だから私は混乱していた。 – user9303

答えて

6

泡は、二つHttpAuthenticatedクラス、suds.transport.httpモジュール内の1つとsuds.transport.httpsモジュールにおける第二を提供します。 suds.transport.httpからインスタンス化されているようですが、URLがhttps://であるため、suds.transport.https.HttpAuthenticatedを試してみるとよいでしょう。

+0

+1。 'suds.transport.https.HttpAuthenticated'はsudsの文書にありませんでした。あなたの解決策は私の問題に対する答えでした。 –

5

私はこの問題に遭遇し、私のために働く解決策を見つけました。 私のサーバはNTLM認証を使用していたので、sudsを使用するには、documentationの「Windows(NTLM)」セクションに従ってください。

まずpython-ntlmをインストールし、あなたが書くことができます:

from suds.transport.https import WindowsHttpAuthenticated 
ntlm = WindowsHttpAuthenticated(username='xx', password='xx') 
client = Client(url, transport=ntlm)