我正在构建一个基于zeep
的Python SOAP客户端。
在我的数据模型设计中,我使用zeep的serialize_object
辅助函数存储序列化响应字典,以进行get
方法调用。我打算允许数据模型dict中的各种键的python对象的数据模型操作,然后能够使用数据模型作为后续update
SOAP调用的参数。
问题是get
响应中返回的值与WSDL的update
定义不匹配。因此,我希望递归地“区分”两个dicts,并删除任何不符合add
定义中要求的密钥。
但是,我不确定如何使用对象工厂Client.get_type()
提取zeep对象的递归dict表示。
我的wsdl包含这个,根据zeep的wsdl转储:
ns0:AddPhoneReq(phone: ns0:XPhone, sequence: xsd:unsignedLong)
XPhone
是:
ns0:XPhone(name: ns0:UniqueString128, description: ns0:String128, product: , class: , protocol: , protocolSide: , callingSearchSpaceName: ns0:XFkType, devicePoolName: ns0:XFkType, commonDeviceConfigName: ns0:XFkType, commonPhoneConfigName: ns0:XFkType, networkLocation: , locationName: ns0:XFkType, mediaResourceListName: ns0:XFkType, networkHoldMohAudioSourceId: , userHoldMohAudioSourceId: , automatedAlternateRoutingCssName: ns0:XFkType, aarNeighborhoodName: ns0:XFkType, loadInformation: ns0:XLoadInformation, vendorConfig: ns0:XVendorConfig, versionStamp: ns0:String128, traceFlag: ns0:boolean, mlppDomainId: ns0:String128, mlppIndicationStatus: , preemption: , useTrustedRelayPoint: , retryVideoCallAsAudio: ns0:boolean, securityProfileName: ns0:XFkType, sipProfileName: ns0:XFkType, cgpnTransformationCssName: ns0:XFkType, useDevicePoolCgpnTransformCss: ns0:boolean, geoLocationName: ns0:XFkType, geoLocationFilterName: ns0:XFkType, sendGeoLocation: ns0:boolean, lines: {({line: ns0:XPhoneLine[]} | {lineIdentifier: ns0:XNumplanIdentifier[]})}, phoneTemplateName: ns0:XFkType, speeddials: {speeddial: ns0:XSpeeddial[]}, busyLampFields: {busyLampField: ns0:XBusyLampField[]}, primaryPhoneName: ns0:XFkType, ringSettingIdleBlfAudibleAlert: , ringSettingBusyBlfAudibleAlert: , blfDirectedCallParks: {blfDirectedCallPark: ns0:XBLFDirectedCallPark[]}, addOnModules: {addOnModule: ns0:XAddOnModule[]}, userLocale: , networkLocale: , idleTimeout: , authenticationUrl: xsd:string, directoryUrl: xsd:string, idleUrl: xsd:string, informationUrl: xsd:string, messagesUrl: xsd:string, proxyServerUrl: xsd:string, servicesUrl: xsd:string, services: {service: ns0:XSubscribedService[]}, softkeyTemplateName: ns0:XFkType, defaultProfileName: ns0:XFkType, enableExtensionMobility: ns0:boolean, singleButtonBarge: , joinAcrossLines: , builtInBridgeStatus: , callInfoPrivacyStatus: , hlogStatus: , ownerUserName: ns0:XFkType, ignorePresentationIndicators: ns0:boolean, packetCaptureMode: , packetCaptureDuration: , subscribeCallingSearchSpaceName: ns0:XFkType, rerouteCallingSearchSpaceName: ns0:XFkType, allowCtiControlFlag: ns0:boolean, presenceGroupName: ns0:XFkType, unattendedPort: ns0:boolean, requireDtmfReception: ns0:boolean, rfc2833Disabled: ns0:boolean, certificateOperation: , authenticationMode: , keySize: , keyOrder: , ecKeySize: , authenticationString: ns0:String128, upgradeFinishTime: xsd:string, deviceMobilityMode: , remoteDevice: ns0:boolean, dndOption: , dndRingSetting: , dndStatus: ns0:boolean, isActive: ns0:boolean, isDualMode: ns0:boolean, mobilityUserIdName: ns0:XFkType, phoneSuite: , phoneServiceDisplay: , isProtected: ns0:boolean, mtpRequired: ns0:boolean, mtpPreferedCodec: , dialRulesName: ns0:XFkType, sshUserId: ns0:String50, sshPwd: ns0:String255, digestUser: ns0:String255, outboundCallRollover: , hotlineDevice: ns0:boolean, secureInformationUrl: ns0:String255, secureDirectoryUrl: ns0:String255, secureMessageUrl: ns0:String255, secureServicesUrl: ns0:String255, secureAuthenticationUrl: ns0:String255, secureIdleUrl: ns0:String255, alwaysUsePrimeLine: , alwaysUsePrimeLineForVoiceMessage: , featureControlPolicy: ns0:XFkType, deviceTrustMode: , earlyOfferSupportForVoiceCall: ns0:boolean, requireThirdPartyRegistration: ns0:boolean, blockIncomingCallsWhenRoaming: ns0:boolean, homeNetworkId: xsd:string, AllowPresentationSharingUsingBfcp: ns0:boolean, confidentialAccess: {confidentialAccessMode: , confidentialAccessLevel: }, requireOffPremiseLocation: ns0:boolean, allowiXApplicableMedia: ns0:boolean, cgpnIngressDN: ns0:XFkType, useDevicePoolCgpnIngressDN: ns0:boolean, msisdn: ns0:String128, enableCallRoutingToRdWhenNoneIsActive: ns0:boolean, wifiHotspotProfile: ns0:XFkType, wirelessLanProfileGroup: ns0:XFkType, elinGroup: ns0:XFkType, ctiid: xsd:positiveInteger)
我可以这样做:
from zeep import Client
from zeep.helpers import serialize_object
client = zeep.Client(**client_kwargs) # client_kwargs just has connection and wsdl info, not shown here...
zeep_obj = client.get_type("ns0:XPhone")
print((serialize_object(zeep_obj)))
但是,这不会返回dict
。
有人建议过滤dict的方法只包括使用zeep返回指定SOAP调用所需的必要键/值吗?是否有更好的方法可以更有效地使用zeep库与wsdl生成的对象进行交互?
答案 0 :(得分:1)
get_type返回一个构造函数。 我有:
xtype = self.__client__.get_type('ns0:XPhone')()
致谢。