我正在构建一个zeep
基于 - 的 Python SOAP 客户端。
在我的数据模型设计中,我使用 zeep 的serialize_object
辅助函数存储序列化响应字典以进行get
方法调用。我打算允许对数据模型字典中的各种键的 python 对象进行数据模型操作,然后能够将数据模型用作后续update
SOAP 调用的参数。
问题是响应中的返回值与 WSDL 的定义get
不匹配。update
因此,我想递归地“区分”这两个字典,并删除任何不符合add
定义要求的键。
但是,我不确定如何使用 object factory 提取 zeep 对象的递归 dict 表示Client.get_type()
。
根据 zeep 的 wsdl 转储,我的 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 生成的对象进行交互?