Python AXL/SOAP w。齐普。如何避免重复的字典键?
Python AXL/SOAP w. Zeep. How to avoid duplicate dictionary keys?
我写了这个请求:
client.updateLdapAuthentication(**{'authenticateEndUsers': authenticateEndUsers, 'distinguishedName': distinguishedName, 'ldapPassword': ldapPassword, 'userSearchBase': userSearchBase, 'servers':{'server': {'hostName': '172.20.23.230', 'ldapPortNumber': '3268', 'sslEnabled': 'false'}}})
这导致了预期的请求:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<ns0:updateLdapAuthentication xmlns:ns0="http://www.cisco.com/AXL/API/11.5">
<authenticateEndUsers>true</authenticateEndUsers>
<distinguishedName>CN=DIRSYNC USER,CN=Users,DC=lab,DC=local</distinguishedName>
<ldapPassword>text</ldapPassword>
<userSearchBase>text</userSearchBase>
<servers>
<server>
<hostName>172.20.23.230</hostName>
<ldapPortNumber>3268</ldapPortNumber>
<sslEnabled>true</sslEnabled>
</server>
</servers>
</ns0:updateLdapAuthentication>
</soap-env:Body>
我正在努力的是用两个服务器条目形成一个请求,如下所示:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<ns0:updateLdapAuthentication xmlns:ns0="http://www.cisco.com/AXL/API/11.5">
<authenticateEndUsers>true</authenticateEndUsers>
<distinguishedName>CN=DIRSYNC USER,CN=Users,DC=lab,DC=local</distinguishedName>
<ldapPassword>text</ldapPassword>
<userSearchBase>text</userSearchBase>
<servers>
<server>
<hostName>172.20.23.230</hostName>
<ldapPortNumber>3268</ldapPortNumber>
<sslEnabled>true</sslEnabled>
</server>
<server>
<hostName>172.20.23.250</hostName>
<ldapPortNumber>3268</ldapPortNumber>
<sslEnabled>true</sslEnabled>
</server>
</servers>
</ns0:updateLdapAuthentication>
</soap-env:Body>
我通过 python -mzeep 检查了 WSDL。这是相关行:
updateLdapAuthentication(authenticateEndUsers: ns0:boolean, distinguishedName: ns0:String128, ldapPassword: ns0:String128, userSearchBase: ns0:String255, servers: {server: {hostName: ns0:String128, ldapPortNumber: , sslEnabled: ns0:boolean}[]}) -> return: ns0:return, sequence: xsd:unsignedLong
所以,我形成了这样的请求:
client.updateLdapAuthentication(**{'authenticateEndUsers': authenticateEndUsers, 'distinguishedName': distinguishedName, 'ldapPassword': ldapPassword, 'userSearchBase': userSearchBase, 'servers':
[{'server': {'hostName': '172.20.23.230',
'ldapPortNumber': '3268',
'sslEnabled': 'false'}},
{'server': {'hostName': '172.20.23.250',
'ldapPortNumber': '3268',
'sslEnabled': 'false'}}]})
它仍然有效,但忽略了第二个服务器条目。有没有人有一些提示如何做到这一点?
我对 updateLdapAuthentication
的参考方式是您没有指定字典列表,而是指定一个带有键 server
的字典,其中有一个字典列表。
所以而不是
[{'server': {'hostName': '172.20.23.230',
'ldapPortNumber': '3268',
'sslEnabled': 'false'}},
{'server': {'hostName': '172.20.23.250',
'ldapPortNumber': '3268',
'sslEnabled': 'false'}}]
尝试
{'server': [{'hostName': '172.20.23.230', 'ldapPortNumber': '3268', 'sslEnabled': 'false'},
{'hostName': '172.20.23.250', 'ldapPortNumber': '3268', 'sslEnabled': 'false'}}]
我写了这个请求:
client.updateLdapAuthentication(**{'authenticateEndUsers': authenticateEndUsers, 'distinguishedName': distinguishedName, 'ldapPassword': ldapPassword, 'userSearchBase': userSearchBase, 'servers':{'server': {'hostName': '172.20.23.230', 'ldapPortNumber': '3268', 'sslEnabled': 'false'}}})
这导致了预期的请求:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<ns0:updateLdapAuthentication xmlns:ns0="http://www.cisco.com/AXL/API/11.5">
<authenticateEndUsers>true</authenticateEndUsers>
<distinguishedName>CN=DIRSYNC USER,CN=Users,DC=lab,DC=local</distinguishedName>
<ldapPassword>text</ldapPassword>
<userSearchBase>text</userSearchBase>
<servers>
<server>
<hostName>172.20.23.230</hostName>
<ldapPortNumber>3268</ldapPortNumber>
<sslEnabled>true</sslEnabled>
</server>
</servers>
</ns0:updateLdapAuthentication>
</soap-env:Body>
我正在努力的是用两个服务器条目形成一个请求,如下所示:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<ns0:updateLdapAuthentication xmlns:ns0="http://www.cisco.com/AXL/API/11.5">
<authenticateEndUsers>true</authenticateEndUsers>
<distinguishedName>CN=DIRSYNC USER,CN=Users,DC=lab,DC=local</distinguishedName>
<ldapPassword>text</ldapPassword>
<userSearchBase>text</userSearchBase>
<servers>
<server>
<hostName>172.20.23.230</hostName>
<ldapPortNumber>3268</ldapPortNumber>
<sslEnabled>true</sslEnabled>
</server>
<server>
<hostName>172.20.23.250</hostName>
<ldapPortNumber>3268</ldapPortNumber>
<sslEnabled>true</sslEnabled>
</server>
</servers>
</ns0:updateLdapAuthentication>
</soap-env:Body>
我通过 python -mzeep 检查了 WSDL。这是相关行:
updateLdapAuthentication(authenticateEndUsers: ns0:boolean, distinguishedName: ns0:String128, ldapPassword: ns0:String128, userSearchBase: ns0:String255, servers: {server: {hostName: ns0:String128, ldapPortNumber: , sslEnabled: ns0:boolean}[]}) -> return: ns0:return, sequence: xsd:unsignedLong
所以,我形成了这样的请求:
client.updateLdapAuthentication(**{'authenticateEndUsers': authenticateEndUsers, 'distinguishedName': distinguishedName, 'ldapPassword': ldapPassword, 'userSearchBase': userSearchBase, 'servers':
[{'server': {'hostName': '172.20.23.230',
'ldapPortNumber': '3268',
'sslEnabled': 'false'}},
{'server': {'hostName': '172.20.23.250',
'ldapPortNumber': '3268',
'sslEnabled': 'false'}}]})
它仍然有效,但忽略了第二个服务器条目。有没有人有一些提示如何做到这一点?
我对 updateLdapAuthentication
的参考方式是您没有指定字典列表,而是指定一个带有键 server
的字典,其中有一个字典列表。
所以而不是
[{'server': {'hostName': '172.20.23.230',
'ldapPortNumber': '3268',
'sslEnabled': 'false'}},
{'server': {'hostName': '172.20.23.250',
'ldapPortNumber': '3268',
'sslEnabled': 'false'}}]
尝试
{'server': [{'hostName': '172.20.23.230', 'ldapPortNumber': '3268', 'sslEnabled': 'false'},
{'hostName': '172.20.23.250', 'ldapPortNumber': '3268', 'sslEnabled': 'false'}}]