我有以下python代码:
import suds
import os
import suds_passworddigest
SERVER_URL = 'http://<address>/onvif/device_service'
WSDL_URL='file:' + os.getcwd() + '/wsdl/devicemgmt.wsdl'
cli=suds.client.Client(WSDL_URL)
cli.set_options(location=SERVER_URL)
security = suds.wsse.Security()
token = suds_passworddigest.UsernameDigestToken('usr', 'password')
#token.setnonce(token.setonce()) # token.setonce() didn't work for me
security.tokens.append(token)
cli.set_options(wsse=security)
list_of_methods = [method for method in cli.wsdl.services[0].ports[0].methods]
print list_of_methods
res=cli.service.GetDNS()
print res
它给出了
AttributeError:'module'对象没有属性'UsernameDigestToken'
我查看了我的导入内容并查看了 suds-passworddigest 的源代码,它的属性为UsernameDigestToken
,这就是为什么我收到此错误。
答案 0 :(得分:0)
更改您的代码,如下所示。 UsernameDigestToken是token.py
的一个属性from suds_passworddigest.token import UsernameDigestToken
...
...
...
token = UsernameDigestToken('usr', 'password')