Python 3.2.2: xmlrpc.client调用中的莫名错误 - "类型'int'的参数不可迭代
跟之前一些问题,比如TypeError: argument of type 'int' is not iterable不一样,我这儿似乎没有明显的索引问题。
在下面的代码中,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:\Users\Administrator\Downloads\randeventmaker\randeventmakerengine.py",
line 861, in <module>
sproxy.execute(initializing_event.eventcommand)
File "C:\Python32\lib\xmlrpc\client.py", line 1095, in __call__
return self.__send(self.__name, args)
File "C:\Python32\lib\xmlrpc\client.py", line 1423, in __request
verbose=self.__verbose
File "C:\Python32\lib\xmlrpc\client.py", line 1136, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\Python32\lib\xmlrpc\client.py", line 1151, in single_request
return self.parse_response(resp)
File "C:\Python32\lib\xmlrpc\client.py", line 1323, in parse_response
return u.close()
File "C:\Python32\lib\xmlrpc\client.py", line 667, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: "<class 'TypeError'>:argument of type 'int' is
not iterable">
2 个回答
0
你可能需要传入一个可迭代的东西,比如一个整数列表...
0
我觉得我至少部分解决了这个问题。显然,远程函数只接受一组参数,也就是一个元组。把
agent_eB.execute(init_event.eventcommand)
改成
agent_eb.execute((init_event.eventcommand,))
似乎解决了这个特定的错误。