Python AXL / SOAP w。 ZEEP。如何避免重复的字典键?

时间:2018-04-16 00:03:05

标签: python soap zeep

我写了这个请求:

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'}}]})

它仍然有效,但忽略了第二个服务器条目。有没有人提示如何做到这一点?

1 个答案:

答案 0 :(得分:0)

我对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'}}]