2010-07-19 125 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