使用pysimplesoap进行身份验证时的问题

0 投票
1 回答
3698 浏览
提问于 2025-04-17 15:37

我正在尝试使用pysimplesoap与Websitepanel的SOAP-API进行通信。

WebsitePanel API的介绍中提到:

要与WebsitePanel API进行交互,你应该使用基本认证。WebsitePanel会识别“Authorization”头部,其中包含的用户凭据格式为:用户名:密码

我第一次尝试是这样的:

client = SoapClient(wsdl=endpoint_url, trace=True)
client['Authorization'] = "%s:%s" % (username, password)

结果返回了401 "未授权"。

第二次尝试是:

client = SoapClient(wsdl=endpoint_url, trace=True)          
client['wsse:Security'] = {
    'wsse:UsernameToken': {
        'wsse:Username': username,
        'wsse:Password': password,
    }
}    

这次按预期工作了,但返回了以下内容:

status: 500
content-length: 924
x-aspnet-version: 4.0.30319
x-powered-by: ASP.NET
server: Microsoft-IIS/7.5
cache-control: private
date: Tue, 12 Feb 2013 14:23:56 GMT
content-type: text/xml; charset=utf-8

还有

pysimplesoap.client.SoapFault: q0:Security: SOAP response should be signed.

为什么 client['Authorization'] 不起作用?“响应应该被签名”这个错误信息是什么意思呢?

提前谢谢你。

1 个回答

3

我搞明白了:要正确地使用pysimplesoap进行身份验证,你需要调用

client = SoapClient(wsdl=u, trace=True, 
                    http_headers={'Authorization': 'Basic %s' % encoded})

这里的 encoded 是一个经过base64编码的字符串,内容是 用户名:密码

撰写回答