【发布时间】:2014-06-20 06:35:18
【问题描述】:
我正在尝试使用来自肥皂定义的网络服务的方法。我能够连接并获取有关方法的信息,但是当我尝试使用该方法时,我收到错误提示
Server raised fault: 'Unspecified parameter 'username''
所以我想当我想向服务器发送数据时,由于某种原因它试图在没有用户名的情况下发送? 我尝试以 suds 文档中描述的各种方式连接(身份验证)到 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 forks,但仍然是同样的问题(具体来说 - suds-jurko 和 suds-ews)。
如何通过指定身份验证(以及其他详细信息,如果之后可能丢失)来强制 suds 使用方法?
更新2 当我像这样更改身份验证实现时(实际上与我上面发布的方法非常相似):
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>
所以我认为以前的方法服务器看不到用户名,但现在由于某种原因它只是拒绝授权?会不会是这样的?
【问题讨论】:
标签: python web-services soap suds