我知道有很多類似的問題 - 這樣的解決方案,但沒有解決方案爲我工作。訪問網絡服務
我想訪問Web服務,但得到HTTP錯誤:401未經授權。
這裏是我的代碼:
from suds.transport.http import HttpAuthenticated
from suds.client import Client
import base64
url = 'http://server.something.com/path/to/Service.svc'
transport = HttpAuthenticated()
client = Client(url,username='******', password='********')
並得到如下錯誤:
Traceback (most recent call last):
File "./getDetails.py", line 127, in <module>
test()
File "./getDetails.py", line 121, in test
client = Client(url,username='****', password='******')
File "/usr/local/lib/python2.7/dist-packages/suds-0.3.7- py2.7.egg/suds/client.py", line 109, in __init__
self.wsdl = Definitions(url, options)
File "/usr/local/lib/python2.7/dist-packages/suds-0.3.7- py2.7.egg/suds/wsdl.py", line 172, in __init__
root = p.parse(url=url).root()
File "/usr/local/lib/python2.7/dist-packages/suds-0.3.7-py2.7.egg/suds/sax/parser.py", line 133, in parse
fp = self.transport.open(Request(url))
File "/usr/local/lib/python2.7/dist-packages/suds-0.3.7-py2.7.egg/suds/transport/https.py", line 69, in open
return HttpTransport.open(self, request)
File "/usr/local/lib/python2.7/dist-packages/suds-0.3.7-py2.7.egg/suds/transport/http.py", line 72, in open
raise TransportError(str(e), e.code, e.fp)
suds.transport.TransportError: HTTP Error 401: Unauthorized
任何幫助將不勝感激。提前致謝。
你好!我認爲你需要設置你的用戶名和密碼作爲標題。您的服務是否暴露任何驗證方法?或有任何認證對象? – israelord
對不起,我沒有得到你。 – mrutyunjay