Python,肥皂水,错误

发布于 2024-09-10 19:05:32 字数 3767 浏览 6 评论 0原文

当我尝试从远程网络服务获取方法时,它给了我错误。

我的代码是:

        portion=10
        start=0
        print self.stamp.datetime
        client=self.client
        while 1:
            print 'getting ids...........'
            fresh_ids=client.service.GetTopicsIDsUpdatedAfterDateTime(self.stamp.datetime,start,portion) #this line makes exception
            if len(fresh_ids) is not 0:
                for id in fresh_ids:
                    yield id
                start=+portion
            else:
                print 'No updated topics anymore'
                sys.exit()

有回溯:

 /usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/client.py
in invoke(self, args, kwargs)
    469         binding = self.method.binding.input
    470         binding.options = self.options
--> 471         msg = binding.get_message(self.method, args, kwargs)
    472         timer.stop()
    473         metrics.log.debug(

/usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/bindings/binding.py
in get_message(self, method, args, kwargs)
     96         content = self.headercontent(method)
     97         header = self.header(content)
---> 98         content = self.bodycontent(method, args, kwargs)
     99         body = self.body(content)
    100         env = self.envelope(header, body)

/usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/bindings/rpc.py
in bodycontent(self, method, args, kwargs)
     61             p = self.mkparam(method, pd, value)
     62             if p is not None:
---> 63                 root.append(p)
     64             n += 1
     65         return root

/usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/sax/element.py
in append(self, objects)
    329                 child.parent = self
    330                 continue
--> 331             raise Exception('append %s not-valid' %
child.__class__.__name__)
    332         return self
    333

<type 'exceptions.Exception'>: append list not-valid

那里是 suds 模块中引发异常的方法:

def insert(self, objects, index=0):
        """
        Insert an L{Element} content at the specified index.
        @param objects: A (single|collection) of attribute(s) or element(s)
            to be added as children.
        @type objects: (L{Element}|L{Attribute})
        @param index: The position in the list of children to insert.
        @type index: int
        @return: self
        @rtype: L{Element}
        """
        objects = (objects,)
        for child in objects:
            if isinstance(child, Element):
                self.children.insert(index, child)
                child.parent = self
            else:
                raise Exception('append %s not-valid' % child.__class__.__name__)
        return self

在控制台中,一切进展顺利。 我被困住了。

好吧,我尝试做一个实验:

def YieldID(self):
        portion=10
        start=0
        print self.stamp.datetime
        fresh_ids=self.client.service.GetTopicsIDsUpdatedAfterDateTime(self.stamp.datetime,start,portion) #This work
        while 1:
            print 'getting ids...........'
            fresh_ids=self.client.service.GetTopicsIDsUpdatedAfterDateTime(self.stamp.datetime,start,portion) # This raise exception
            if len(fresh_ids)!=0:
                for id in fresh_ids:
                    yield id
                start=+portion
            else:
                print 'No updated topics anymore'
                sys.exit()

我在结束工作之前添加了对相同方法的调用。但当它进去时却给了我例外。

它如何在循环之前工作,而在循环内部不起作用?这是主要问题。发生了什么变化?

我什至尝试将 while 更改为 for

When I'm trying get method from remote webservice it gives me error.

My code is:

        portion=10
        start=0
        print self.stamp.datetime
        client=self.client
        while 1:
            print 'getting ids...........'
            fresh_ids=client.service.GetTopicsIDsUpdatedAfterDateTime(self.stamp.datetime,start,portion) #this line makes exception
            if len(fresh_ids) is not 0:
                for id in fresh_ids:
                    yield id
                start=+portion
            else:
                print 'No updated topics anymore'
                sys.exit()

There is trace-back:

 /usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/client.py
in invoke(self, args, kwargs)
    469         binding = self.method.binding.input
    470         binding.options = self.options
--> 471         msg = binding.get_message(self.method, args, kwargs)
    472         timer.stop()
    473         metrics.log.debug(

/usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/bindings/binding.py
in get_message(self, method, args, kwargs)
     96         content = self.headercontent(method)
     97         header = self.header(content)
---> 98         content = self.bodycontent(method, args, kwargs)
     99         body = self.body(content)
    100         env = self.envelope(header, body)

/usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/bindings/rpc.py
in bodycontent(self, method, args, kwargs)
     61             p = self.mkparam(method, pd, value)
     62             if p is not None:
---> 63                 root.append(p)
     64             n += 1
     65         return root

/usr/lib/python2.5/site-packages/suds-0.3.5-py2.5.egg/suds/sax/element.py
in append(self, objects)
    329                 child.parent = self
    330                 continue
--> 331             raise Exception('append %s not-valid' %
child.__class__.__name__)
    332         return self
    333

<type 'exceptions.Exception'>: append list not-valid

There is the method in suds module which raises an Exception:

def insert(self, objects, index=0):
        """
        Insert an L{Element} content at the specified index.
        @param objects: A (single|collection) of attribute(s) or element(s)
            to be added as children.
        @type objects: (L{Element}|L{Attribute})
        @param index: The position in the list of children to insert.
        @type index: int
        @return: self
        @rtype: L{Element}
        """
        objects = (objects,)
        for child in objects:
            if isinstance(child, Element):
                self.children.insert(index, child)
                child.parent = self
            else:
                raise Exception('append %s not-valid' % child.__class__.__name__)
        return self

In the console everything is going well.
I'm stuck.

Ok, I tried to make an experiment:

def YieldID(self):
        portion=10
        start=0
        print self.stamp.datetime
        fresh_ids=self.client.service.GetTopicsIDsUpdatedAfterDateTime(self.stamp.datetime,start,portion) #This work
        while 1:
            print 'getting ids...........'
            fresh_ids=self.client.service.GetTopicsIDsUpdatedAfterDateTime(self.stamp.datetime,start,portion) # This raise exception
            if len(fresh_ids)!=0:
                for id in fresh_ids:
                    yield id
                start=+portion
            else:
                print 'No updated topics anymore'
                sys.exit()

I add calling of the same method before WHILE end it work. But when it go inside while gives me exception.

How it can work before loop, and don't work inside loop? That is the main question. What changed?

I even tried changing while to for.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-柠檬树下少年和吉他 2024-09-17 19:05:32

编辑:再看一下代码,我注意到这一行:

            start=+portion

需要更改为

            start += portion

这可能会使以下分析变得不必要......但我认为仍然可能是您的肥皂水源中的一个问题,如下所述。


我要问的第一个问题是:您确定在调用 YieldID 之间,您的 self.client 对象内部没有任何变化吗?

我的另一个担忧——这很可能根本没有任何迹象——是您可能为引发异常的函数发布了错误的源代码。回溯显示,在调用 append 期间引发了异常,但您包含的代码用于 insert。由于复制和粘贴错误,insert 的异常消息似乎将其标识为“append”。

还有更多。假设我已经确定了正确的源位置,这是 append 的完整源代码,从第 313 行开始:

def append(self, objects):
    """
    Append the specified child based on whether it is an
    element or an attrbuite.
    @param objects: A (single|collection) of attribute(s) or element(s)
        to be added as children.
    @type objects: (L{Element}|L{Attribute})
    @return: self
    @rtype: L{Element}
    """
    if not isinstance(objects, (list, tuple)):
        objects = (objects,)
    for child in objects:
        if isinstance(child, Element):
            self.children.append(child)
            child.parent = self
            continue
        if isinstance(child, Attribute):
            self.attributes.append(child)
            child.parent = self
            continue
        raise Exception('append %s not-valid' % child.__class__.__name__)
    return self

这里,异常是在第 334 行引发的,而不是在 331 上引发的正如你的回溯所示。

您确定使用的是 suds 0.3.5 的原始版本,而不是修改版本吗?因为 append 的原始版本与 有一个有趣的区别>insert: insert always 从其输入参数中创建一个元组,这充其量看起来是多余的:

def insert(self, objects, index=0): // line 337
    # ... snip to line 348
    objects = (objects,)

而原始的 append 确实如此有条件地执行此操作(见上文):

    if not isinstance(objects, (list, tuple)):
        objects = (objects,)

现在查看异常中的消息:

:追加
列表无效

这意味着它尝试附加的子项本身就是一个列表。但这怎么可能呢?如果一个列表作为输入传入,那么我们应该迭代该列表的子项......它们本身不应该是列表。

唔。也许双重嵌套列表已作为对象参数传递到 append 中,这似乎表明数据结构出现了一些相当严重的损坏。 (请参阅我的第一个问题。)

或者...

接下来的内容纯粹是猜测,不可能是正确的...除非...

或者,也许,您正在使用修改后的Suds 的版本中,删除了对列表的条件转换以及列表的迭代?这可以解释您发布的代码和我在网上找到的源代码之间的 3 行差异(331 与 334)。您能否仔细检查您正在使用的源文件,并让我们确定?

Edit: On another look at the code, I noticed that this line:

            start=+portion

needs to be changed to

            start += portion

That might make the following analysis unnecessary... but I think there might still be an issue in your suds source, as explained below.


The first question I'd ask is: Are you sure that nothing is changing inside your self.client object between calls to YieldID?

The other concern I have -- which may well be indicative of nothing at all -- is that you may have posted the wrong source for the function where the Exception is raised. The traceback shows that the Exception is raised during a call to append, but the code you included is for insert. It looks as if insert's Exception message identifies it as "append" due to a copy and paste error.

And there's more. Assuming that I've identified the right source location, here's the full source for append, which starts with line number 313:

def append(self, objects):
    """
    Append the specified child based on whether it is an
    element or an attrbuite.
    @param objects: A (single|collection) of attribute(s) or element(s)
        to be added as children.
    @type objects: (L{Element}|L{Attribute})
    @return: self
    @rtype: L{Element}
    """
    if not isinstance(objects, (list, tuple)):
        objects = (objects,)
    for child in objects:
        if isinstance(child, Element):
            self.children.append(child)
            child.parent = self
            continue
        if isinstance(child, Attribute):
            self.attributes.append(child)
            child.parent = self
            continue
        raise Exception('append %s not-valid' % child.__class__.__name__)
    return self

Here, the Exception is raised on line 334, not 331 as your traceback shows.

Are you sure that you're using the original version of suds 0.3.5, and not a modified version? Because the original version of append has an interesting difference with insert: insert always creates a tuple out of its input argument, which seems redundant at best:

def insert(self, objects, index=0): // line 337
    # ... snip to line 348
    objects = (objects,)

whereas the original append does this conditionally (see above):

    if not isinstance(objects, (list, tuple)):
        objects = (objects,)

Now look at the message in the exception:

: append
list not-valid

This means that the child that it tried to append was itself a list. But how could this be? If a list had been passed in as input, then we should be iterating through the children of that list... which should not themselves be lists.

Hmm. Perhaps a doubly-nested list had been passed into append as the object parameter, which would seem to indicate some pretty bad corruption of data structures. (See my first question.)

Or...

What follows is sheer speculation, and can't possibly be right ... unless it is...

Or, maybe, you're using a modified version of Suds in which that conditional conversion to a list has been removed, along with the iteration through the list? That would explain the 3-line difference (331 vs. 334) between the code you posted and the source that I found online. Could you double-check the source file that you're using, and let us know for sure?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文