當我試圖從遠程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
。
與你的問題沒有關係,但是如果len(fresh_ids)不是0:'不是一個好主意。至少使用'如果len(fresh_ids)!= 0:',或者簡單地'如果len(fresh_ids):' – 2010-07-19 14:52:04
是的,但異常開始於那部分代碼之前。但無論如何,我改變了它。謝謝。 – Pol 2010-07-19 14:53:38
_your_代碼中的哪一行導致異常? – Thomas 2010-07-19 14:56:32