Python AXL/SOAP w. Zeep. How to avoid duplicate dictionary keys?

╄→гoц情女王★ 提交于 2020-01-04 09:41:42

问题


I wrote this request:

client.updateLdapAuthentication(**{'authenticateEndUsers': authenticateEndUsers, 'distinguishedName': distinguishedName, 'ldapPassword': ldapPassword, 'userSearchBase': userSearchBase, 'servers':{'server': {'hostName': '172.20.23.230', 'ldapPortNumber': '3268', 'sslEnabled': 'false'}}})

This resulted in the expected request:

<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>

What I'm struggeling with is forming a request with two server entries like this:

<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>

I checked the WSDL via python -mzeep. This is the relevant line:

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

So, I formed a request like this:

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

It still works, but ignores the second server entry. Has anyone some hints how to do this?


回答1:


The way I your reference for updateLdapAuthentication is that you do not specify a list of dictionaries but one dictionary with a key server which has a list of dictionaries. So instead of

[{'server': {'hostName': '172.20.23.230',
             'ldapPortNumber': '3268',
             'sslEnabled': 'false'}},
 {'server': {'hostName': '172.20.23.250',
             'ldapPortNumber': '3268',
             'sslEnabled': 'false'}}]

try

{'server': [{'hostName': '172.20.23.230', 'ldapPortNumber': '3268', 'sslEnabled': 'false'},
            {'hostName': '172.20.23.250', 'ldapPortNumber': '3268', 'sslEnabled': 'false'}}]


来源:https://stackoverflow.com/questions/49847976/python-axl-soap-w-zeep-how-to-avoid-duplicate-dictionary-keys

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!