Not able to create a SOAP filter in suds

时光毁灭记忆、已成空白 提交于 2019-11-28 14:10:00

After debugging and going through some suds code, I have found the fix.

The complete code snippet of the fix:

inputElement = client.factory.create('CreateExportJobRequest')

inputElement.ExportJobTypeName = "Products"
inputElement.ExportColumns.ExportColumn = ["Id", "itemName"]

inputElement.Frequency = 'ONETIME'

if updatedSince:
    efilter = client.factory.create("ExportFilter")
    efilter._id = 'updatedSince'
    efilter.Text = updatedSince
    inputElement.ExportFilters.ExportFilter.append(efilter)

t = client.service.CreateExportJob(inputElement.ExportJobTypeName, inputElement.ExportColumns, inputElement.ExportFilters, None, None, inputElement.Frequency)

Debugging: Because suds was raising TypeNotFound exception, I looked for all the places that raise TypeNotFound inside suds. I put debug points in my PyCharm.

I found that the start method from Typed class inside suds/mx/literal.py was raising the error I was getting.

def start(self, content):
    #
    # Start marshalling the 'content' by ensuring that both the
    # 'content' _and_ the resolver are primed with the XSD type
    # information.  The 'content' value is both translated and
    # sorted based on the XSD type.  Only values that are objects
    # have their attributes sorted.
    #
    log.debug('starting content:\n%s', content)
    if content.type is None:
        name = content.tag
        if name.startswith('_'):
            name = '@'+name[1:]
        content.type = self.resolver.find(name, content.value)
        if content.type is None:
            raise TypeNotFound(content.tag)
    else:
        known = None
        if isinstance(content.value, Object):
            known = self.resolver.known(content.value)
            if known is None:
                log.debug('object has no type information', content.value)
                known = content.type
        frame = Frame(content.type, resolved=known)
        self.resolver.push(frame)
    frame = self.resolver.top()
    content.real = frame.resolved
    content.ancestry = frame.ancestry
    self.translate(content)
    self.sort(content)
    if self.skip(content):
        log.debug('skipping (optional) content:\n%s', content)
        self.resolver.pop()
        return False
    else:
        return True

So from this logic, I came to the fix.

But, It would be really great if somebody suggests a standard procedure for this.

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