在 python 中,调用 XML-RPC 方法涉及调用代理对象上的方法:
from xmlrpclib import ServerProxy
print ServerProxy('https://example.com/rpc').api.hello_there('John')
在其他一些语言中,例如 perl,您可以将方法名称作为方法参数传递。
use Frontier::Client;
$p = Frontier::Client->new(url => 'https://example.com/rpc');
$result = $p->call('api.hello_there', 'John');
print $result;
有没有办法在 Python 中按名称(作为字符串)调用 XML-RPC 方法?
只需使用getattr
,与任何 Python 对象一样。
func = getattr(ServerProxy('https://example.com/rpc'), "api.hello_there")
print func('John')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)