访问Web服务

时间:2014-04-10 13:14:00

标签: python web-services suds

我知道有许多类似的问题 - 像这样的解决方案,但没有一个解决方案适合我。

我正在尝试访问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

任何帮助将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:0)

不知道这是否解决您的问题,但我建议您使用此库Requests

实施例

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

根据您的代码,您指向根服务而不是方法。