SUDS调用中的意外元素

时间:2015-03-17 18:46:48

标签: python soap suds

我对Web服务的了解有限,但听起来像使用SUDS制作客户端可能是直截了当的。我从客户端访问的WSDL和导入的模式相当复杂(从我的角度来看)。这是我的剧本:

import logging
from suds.client import Client

logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)

url_service = 'http://cds1:8080/process/services/ProcessManagement?wsdl'

client = Client(url_service)
print(client)

schedule_criterion = client.factory.create('{http://xml.spss.com/prms}scheduleCriterion')
return_specifier = client.factory.create('{http://xml.spss.com/prms}returnSpecifier')
page_selector = client.factory.create('{http://xml.spss.com/prms}pageSelector')

return_specifier._sortOrder = "Ascending"
schedule_criterion.returnSpecifier = return_specifier
schedule_criterion.pageSelector = page_selector

response = client.service.querySchedules(schedule_criterion)

以下是print(client)的输出。有多个架构:

Service ( ProcessManagementService ) tns="http://xml.spss.com/prms/wsdl"
   Prefixes (4)
      ns0 = "http://www.spss.com/pes/pager"
      ns1 = "http://xml.spss.com/prms"
      ns2 = "http://xml.spss.com/prms/exception"
      ns3 = "http://xml.spss.com/prms/remote"
   Ports (1):
      (ProcessManagement)
         Methods (33):
            cancelExecution(xs:string executionID, )
            createMessageDrivenJob(xs:string jobLocationURI, ns1:messageDrivenJobSpecifier messageDrivenJobIn, )
            createSchedule(xs:string jobLocationURI, ns1:scheduleSpecifier scheduleIn, )
            deleteJobExecutions(xs:string[] jobExecutionIDs, )
            deleteJobTrigger(xs:string objectID, )
            deleteJobTriggers(xs:string[] objectID, )
            deleteSchedule(xs:string scheduleID, )
            deleteSchedules(xs:string[] scheduleID, )
            finalizeRemoteWork(ns1:remoteWorkCompletion remoteWorkCompletion, )
            getCustomEventTypes()
            getExecutionDetails(xs:string executionID, ns1:deliveryType deliveryType, )
            getJobParameters(xs:string jobLocationURI, )
            getJobStepChildExecutions(xs:string jobStepExecutionID, ns1:deliveryType deliveryType, )
            getJobStepExecutions(xs:string jobExecutionID, ns1:deliveryType deliveryType, )
            getMessageDrivenJob(xs:string messageDrivenJobID, )
            getMessageDrivenJobs(xs:string jobLocationURI, )
            getSchedule(xs:string scheduleID, )
            getSchedules(xs:string jobLocationURI, )
            getVersion()
            getWorkTypes()
            handleMessageDomainChanged(xs:string msgDomainID, )
            queryAllSchedules(ns1:jobTriggerCriterion jobTriggerCriterion, )
            queryExecutions(ns1:executionCriterion executionCriterion, )
            queryJobTriggers(ns1:jobTriggerCriterion jobTriggerCriterion, )
            querySchedules(ns1:scheduleCriterion scheduleCriterion, )
            querySubmittedExecutions(ns1:submittedExecutionCriterion submittedExecutionCriterion, )
            rerunFailedJobStepIterations(xs:string oldJobStepExecutionID, )
            submitEventCluster(ns1:eventClusterSpec eventClusterSpec, )
            submitJob(xs:string jobLocationURI, xs:boolean notificationEnabled, )
            submitJobWithOptions(xs:string jobLocationURI, ns1:jobOptions jobOptions, )
            submitWork(ns1:workSpec workSpec, )
            updateMessageDrivenJob(ns1:messageDrivenJobSpecifier messageDrivenJobIn, )
            updateSchedule(ns1:scheduleSpecifier scheduleIn, )
         Types (103):
            ns0:ColumnType
            ns0:ColumnTypeColTypeType
            ns1:CompletionStatusType
            ns0:NavigatorItem
            ns1:ReturnSpecifierSortOrderType
            ns0:RowType
            ns1:StringWithWhiteSpace
            ns1:addObject
            ns1:addRelationship
            ns1:attachment
            ns1:attributeValuePair
            ns2:authorizationException
            ns1:cascadingEventRelationship
            ns1:cleanupErrorProcessingType
            ns1:cleanupOptions
            ns1:cleanupType
            ns1:commandWork
            ns2:concurrentUpdateException
            ns1:criterion
            ns1:customEvent
            ns1:customWork
            ns1:dailySchedule
            ns2:databaseException
            ns1:dateRange
            ns1:deleteObject
            ns1:deleteRelationship
            ns1:deliveryType
            ns2:duplicateNameException
            ns1:event
            ns1:eventCluster
            ns1:eventClusterReference
            ns1:eventClusterSpec
            ns1:eventExecution
            ns1:eventExecutionMode
            ns1:eventExecutionState
            ns1:eventFlow
            ns1:execSpec
            ns1:executionCriterion
            ns1:executionDetails
            ns1:executionFilter
            ns1:failureConsequences
            ns1:filter
            ns1:flowType
            ns1:genericWork
            ns1:hourlySchedule
            ns2:invalidStateException
            ns1:jobOptions
            ns1:jobParameter
            ns1:jobParameterValue
            ns1:jobParameterValues
            ns1:jobParameters
            ns1:jobStepChildExecutions
            ns1:jobTriggerCriterion
            ns1:jobTriggerFilter
            ns1:log
            ns1:messageDomain
            ns1:messageDomainType
            ns1:messageDrivenJob
            ns1:messageDrivenJobList
            ns1:messageDrivenJobSpecifier
            ns1:messageDrivenJobstep
            ns1:month
            ns1:monthlySchedule
            ns2:objectNotFoundException
            ns1:onceSchedule
            ns1:pageRequest
            ns0:pageResultSortOrderType
            ns1:pageSelector
            ns1:processObject
            ns1:recurringSchedule
            ns1:referenceById
            ns1:referenceByObject
            ns1:referenceObject
            ns2:relatedObjectException
            ns1:relationship
            ns1:relativeDay
            ns1:relativeMonthlySchedule
            ns1:relativeOccurrence
            ns1:remoteWorkCompletion
            ns1:remoteWorkRequest
            ns1:returnSpecifier
            ns1:schedule
            ns1:scheduleCriterion
            ns1:scheduleFilter
            ns1:scheduleList
            ns1:scheduleSpecifier
            ns1:scheduledEventClusterRelationship
            ns2:schedulingException
            ns1:sortableCriterion
            ns1:submittedExecutionCriterion
            ns1:submittedExecutionFilter
            ns1:updateAttributes
            ns1:updateCommand
            ns1:updateVersionLabel
            ns1:updates
            ns1:waitForParents
            ns1:weeklySchedule
            ns1:windowsCommandWork
            ns1:work
            ns1:workEvent
            ns1:workEventToWorkRelationship
            ns1:workSpec
            ns1:yearlySchedule

Service ( RemoteProcessService ) tns="http://xml.spss.com/prms/wsdl"
   Prefixes (4)
      ns4 = "http://www.spss.com/pes/pager"
      ns5 = "http://xml.spss.com/prms"
      ns6 = "http://xml.spss.com/prms/exception"
      ns7 = "http://xml.spss.com/prms/remote"
   Ports (1):
      (RemoteProcess)
         Methods (4):
            cancelRemoteWork(xs:string executionID, )
            executeRemoteShutdown()
            executeRemoteWork(ns5:remoteWorkRequest remoteWorkRequest, )
            remoteServerActive()
         Types (103):
            ns4:ColumnType
            ns4:ColumnTypeColTypeType
            ns5:CompletionStatusType
            ns4:NavigatorItem
            ns5:ReturnSpecifierSortOrderType
            ns4:RowType
            ns5:StringWithWhiteSpace
            ns5:addObject
            ns5:addRelationship
            ns5:attachment
            ns5:attributeValuePair
            ns6:authorizationException
            ns5:cascadingEventRelationship
            ns5:cleanupErrorProcessingType
            ns5:cleanupOptions
            ns5:cleanupType
            ns5:commandWork
            ns6:concurrentUpdateException
            ns5:criterion
            ns5:customEvent
            ns5:customWork
            ns5:dailySchedule
            ns6:databaseException
            ns5:dateRange
            ns5:deleteObject
            ns5:deleteRelationship
            ns5:deliveryType
            ns6:duplicateNameException
            ns5:event
            ns5:eventCluster
            ns5:eventClusterReference
            ns5:eventClusterSpec
            ns5:eventExecution
            ns5:eventExecutionMode
            ns5:eventExecutionState
            ns5:eventFlow
            ns5:execSpec
            ns5:executionCriterion
            ns5:executionDetails
            ns5:executionFilter
            ns5:failureConsequences
            ns5:filter
            ns5:flowType
            ns5:genericWork
            ns5:hourlySchedule
            ns6:invalidStateException
            ns5:jobOptions
            ns5:jobParameter
            ns5:jobParameterValue
            ns5:jobParameterValues
            ns5:jobParameters
            ns5:jobStepChildExecutions
            ns5:jobTriggerCriterion
            ns5:jobTriggerFilter
            ns5:log
            ns5:messageDomain
            ns5:messageDomainType
            ns5:messageDrivenJob
            ns5:messageDrivenJobList
            ns5:messageDrivenJobSpecifier
            ns5:messageDrivenJobstep
            ns5:month
            ns5:monthlySchedule
            ns6:objectNotFoundException
            ns5:onceSchedule
            ns5:pageRequest
            ns4:pageResultSortOrderType
            ns5:pageSelector
            ns5:processObject
            ns5:recurringSchedule
            ns5:referenceById
            ns5:referenceByObject
            ns5:referenceObject
            ns6:relatedObjectException
            ns5:relationship
            ns5:relativeDay
            ns5:relativeMonthlySchedule
            ns5:relativeOccurrence
            ns5:remoteWorkCompletion
            ns5:remoteWorkRequest
            ns5:returnSpecifier
            ns5:schedule
            ns5:scheduleCriterion
            ns5:scheduleFilter
            ns5:scheduleList
            ns5:scheduleSpecifier
            ns5:scheduledEventClusterRelationship
            ns6:schedulingException
            ns5:sortableCriterion
            ns5:submittedExecutionCriterion
            ns5:submittedExecutionFilter
            ns5:updateAttributes
            ns5:updateCommand
            ns5:updateVersionLabel
            ns5:updates
            ns5:waitForParents
            ns5:weeklySchedule
            ns5:windowsCommandWork
            ns5:work
            ns5:workEvent
            ns5:workEventToWorkRelationship
            ns5:workSpec
            ns5:yearlySchedule

我的错误:

DEBUG:suds.client:headers = {'SOAPAction': '""', 'Content-Type': 'text/xml; charset=utf-8'}
ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://xml.spss.com/prms/remote" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://xml.spss.com/prms" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <ns1:Body>
      <ns0:querySchedules>
         <ns0:scheduleCriterion>
            <ns2:returnSpecifier sortOrder="Ascending"/>
         </ns0:scheduleCriterion>
      </ns0:querySchedules>
   </ns1:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:http failed:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header/><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Unmarshalling Error: unexpected element (uri:"http://xml.spss.com/prms/remote", local:"scheduleCriterion"). Expected elements are &lt;{http://xml.spss.com/prms}scheduleCriterion> </faultstring></soap:Fault></soap:Body></soap:Envelope>
Traceback (most recent call last):
  File "spss_cads_app/scripts/ws1.py", line 31, in <module>
    main()
  File "spss_cads_app/scripts/ws1.py", line 26, in main
    response = client.service.querySchedules(schedule_criterion)
  File "/spss_cads_ve/local/lib/python2.7/site-packages/suds/client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "/spss_cads_ve/local/lib/python2.7/site-packages/suds/client.py", line 602, in invoke
    result = self.send(soapenv)
  File "/spss_cads_ve/local/lib/python2.7/site-packages/suds/client.py", line 649, in send
    result = self.failed(binding, e)
  File "/spss_cads_ve/local/lib/python2.7/site-packages/suds/client.py", line 702, in failed
    r, p = binding.get_fault(reply)
  File "/spss_cads_ve/local/lib/python2.7/site-packages/suds/bindings/binding.py", line 265, in get_fault
    raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'Unmarshalling Error: unexpected element (uri:"http://xml.spss.com/prms/remote", local:"scheduleCriterion"). Expected elements are <{http://xml.spss.com/prms}scheduleCriterion> '

我认为scheduleCriterion不在预期的命名空间中,尽管我使用factory.create({http://xml.spss.com/prms}scheduleCriterion)来实现它。基于SUDS在SOAP信封中分配ns#标签的方式,我认为它应该使用ns2。我正确地解释了这个问题吗?我希望我能忽略一些简单的事情,因为我的下一个方法是明确地构建信封,等等。任何帮助都将非常感激。感谢。

1 个答案:

答案 0 :(得分:0)

经过进一步搜索,我在这里找到了答案。这是我的确切问题。

python suds wrong namespace prefix in SOAP request