与之前的问题(如TypeError)不同:类型为';int';是不可迭代的——在我的情况下,似乎没有立即明显的索引问题。
在下面的代码中,testcfg.agents
是主机名和/或IP地址的列表,testcfg.port
是xmlrpc
调用应使用的端口。DSEvent
类为Active Directory中的事件建模,DSEvent.eventcommand
是一个包含命令及其参数的列表(通过xmlrpc
调用传递给代理,代理使用subprocess
模块执行该命令)
# Create a list of agents to process events from
agent_list = []
for a in testcfg.agents:
agent_list.append(xmlrpc.client.ServerProxy("http://" + a + ':' + testcfg.port))
# Initial user creation:
for j in range(5):
init_event = DSEvent(type = 'add', is_important = True)
agent_eB = random.choice(agent_list)
agent_eB.execute(init_event.eventcommand) # This line throws the fault described below!
我得到的确切例外是(去掉了对模块的各种回溯):
xmlrpc.client.Fault: <Fault 1: "<class 'TypeError'>:argument of type 'int' is not iterable">
我不明白这个错误可能是从哪里来的。虽然init_event.eventcommand
是一个可迭代对象(列表),但我在其他代码中通过xmlrpc
传递并返回了可迭代对象,没有遇到这个错误。我已经检查了意外变量重用,我认为这也不是问题所在。我真的很想在这里得到帮助!
作为参考,以下是此错误的完整回溯:
Traceback (most recent call last):
File "C:UsersAdministratorDownloadsrandeventmakerrandeventmakerengine.py",
line 861, in <module>
sproxy.execute(initializing_event.eventcommand)
File "C:Python32libxmlrpcclient.py", line 1095, in __call__
return self.__send(self.__name, args)
File "C:Python32libxmlrpcclient.py", line 1423, in __request
verbose=self.__verbose
File "C:Python32libxmlrpcclient.py", line 1136, in request
return self.single_request(host, handler, request_body, verbose)
File "C:Python32libxmlrpcclient.py", line 1151, in single_request
return self.parse_response(resp)
File "C:Python32libxmlrpcclient.py", line 1323, in parse_response
return u.close()
File "C:Python32libxmlrpcclient.py", line 667, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: "<class 'TypeError'>:argument of type 'int' is
not iterable">
您可能需要传入一个可迭代的,比如一个整数列表。。。
我想我已经解决了这个问题,至少部分解决了。显然,远程函数仅接受一个参数元组。更改
agent_eB.execute(init_event.eventcommand)
至
agent_eb.execute((init_event.eventcommand,))
似乎已经修复了这个特定的错误。