簡體   English   中英

訪問網絡服務

[英]Accessing web services

我知道有很多類似的問題解決方案,例如這種解決方案,但是沒有一種解決方案適合我。

我正在嘗試訪問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

任何幫助將不勝感激。 提前致謝。

不知道這是否解決您的問題,但我建議你使用這個庫的要求

import requests
response = requests.get('https://api.github.com/user', auth=('user', 'pass'))

根據您的代碼,您指向的是根服務而不是方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM