2010-07-19 100 views
0

当我试图从远程web服务获取方法,它给了我错误。Python,泡沫,错误

我的代码是:

 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

+0

与你的问题没有关系,但是如果len(fresh_ids)不是0:'不是一个好主意。至少使用'如果len(fresh_ids)!= 0:',或者简单地'如果len(fresh_ids):' – 2010-07-19 14:52:04

+0

是的,但异常开始于那部分代码之前。但无论如何,我改变了它。谢谢。 – Pol 2010-07-19 14:53:38

+0

_your_代码中的哪一行导致异常? – Thomas 2010-07-19 14:56:32

回答

2

编辑:在另一方面看代码,我注意到,这条线:需要

  start=+portion 

改变到

  start += portion 

这可能会做如下分析不必要的...但我认为可能仍然是您的泡沫源中的问题,如下所述。


我问的第一个问题是:你确信没有什么是调用之间的self.client对象内部更改为YieldID

我所关心的另一个问题 - 很可能完全没有任何迹象 - 就是您可能在提出异常的地方发布了错误的函数源。追溯显示在调用append期间引发异常,但您包含的代码是insert。看起来好像insert的异常消息由于复制和粘贴错误而将其标识为“追加”。

还有更多。假设我已经确定了right source location,下面是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 

在这里,唯一的例外是上线提出,不为您追踪显示。

您确定您使用的是原始版本的泡沫0.3.5,而不是修改后的版本吗?由于append原始版本与insert一个有趣的差异:insert总是创建一个元组出它的输入参数,这似乎在冗余最好的:

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)。您可以仔细检查您使用的源文件,并确保通知我们吗?

+0

你说得对。这不是我的追溯,我瘦了,它像我的一样。我只是不能复制我的控制台,并找到类似的回溯在一些论坛。抱歉。我在想,这是真的吗。 – Pol 2010-07-19 18:23:12

+0

谢谢。在你使用的库中,'append'的定义是否与原始版本相匹配,还是被修改了? – 2010-07-19 18:25:59

+1

它没有修改! – Pol 2010-07-19 21:53:07