执行python的时候遇到这个错误:
def write_files_to(self,files=None,data=None,run_as_root=False,timeout=120, create=True,*files,**data)
调用的时候:
r = client.call({}, "write_files_to", files=["/tmp/test","/tmp/test1"],
data=base64.b64encode(b'1234'))
这个时候就报出上述错误:
Traceback (most recent call last):
File “/root/codes/sahara-agent/.tox/venv/lib/python3.6/site-packages/oslo_messaging/rpc/server.py”, line 165, in _process_incoming
res = self.dispatcher.dispatch(message)
File “/root/codes/sahara-agent/.tox/venv/lib/python3.6/site-packages/oslo_messaging/rpc/dispatcher.py”, line 276, in dispatch
return self._do_dispatch(endpoint, method, ctxt, args)
File “/root/codes/sahara-agent/.tox/venv/lib/python3.6/site-packages/oslo_messaging/rpc/dispatcher.py”, line 196, in _do_dispatch
result = func(ctxt, **new_args)
TypeError: write_files_to() got multiple values for argument ‘files’
函数传入的参数是一个list,默认成了传入的是两个参数值,导致在调用时以为传入两个参数,从而报错
确实要传多个参数:可以利用python传参的性质(*files,**data),这样写就可以通过:
def write_files_to(self,run_as_root=False,timeout=120, create=True,*files,**data):