xmlrpclib

Can XML-RPC methods be called by name (as strings) in Python?

蓝咒 提交于 2019-12-06 03:49:33
In python, calling XML-RPC methods involves invoking methods on a proxy object: from xmlrpclib import ServerProxy print ServerProxy('https://example.com/rpc').api.hello_there('John') In some other languages, like perl, you pass your method name as a method parameter. use Frontier::Client; $p = Frontier::Client->new(url => 'https://example.com/rpc'); $result = $p->call('api.hello_there', 'John'); print $result; Is there a way to invoke XML-RPC methods by name, as strings, in Python? Just use getattr , as with any Python object. func = getattr(ServerProxy('https://example.com/rpc'), "api.hello

监控log文件,将得到的ip写入redis数据库

孤者浪人 提交于 2019-12-05 15:22:32
服务器端 将得到的 ip 写入数据库: #! /usr/bin/env python # encoding: utf-8 # time : 2015-06-02 9:55:24 # use : rpc # 在 192.168.8.214 建立服务器端,用函数 redis_records_add 在 redis 中处理 ip import sys import redis reload(sys) sys.setdefaultencoding('utf8') from SimpleXMLRPCServer import SimpleXMLRPCServer def redis_con(host): r = redis.Redis(host='%s' % host, port='6379') return r def redis_records_add(key, value): try: conn = redis_con('192.168.8.214') # 判断 key 是否在 redis 中已经有值,如果有那么自增 1 ,如果没有 那么设置为 1 if conn.zscore(key, value): redis_score = int(conn.zscore(key, value))+1 conn.zadd(key, value, redis_score) return conn

How do we handle Python xmlrpclib Connection Refused?

こ雲淡風輕ζ 提交于 2019-12-05 08:27:25
I don't know what the heck I'm doing wrong here, I wrote have an RPC client trying to connect to a non-existent server, and I'm trying to handle the exception that is thrown, but no matter what I try I can't figure out how I'm supposed to handle this: def _get_rpc(): try: a = ServerProxy('http://dd:LNXFhcZnYshy5mKyOFfy@127.0.0.1:9001') a = a.supervisor return a except: return False rpc = _get_rpc() if not rpc: print "No RPC" Since there is no server running, I would expect the output to be "No RPC" but instead I get an exception: Traceback (most recent call last): File "xmlrpctest.py", line 20

How to install xmlrpclib in python 3.4?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 23:18:22
When I am trying to install xmlrpclib, I am getting following error in python version 3.4 Downloading/unpacking xmlrpclib Could not find any downloads that satisfy the requirement xmlrpclib Some externally hosted files were ignored (use --allow-external xmlrpclib to allow). Cleaning up... No distributions at all found for xmlrpclib Storing debug log for failure in /home/shiva/.pip/pip.log How to install xmlrpclib in python 3.4 ? xmlrpclib is part of the standard library in Python 2.x. It's not a package that you need to install. In Python 3.x you can import it from xmlrpc instead: https://docs

How can I add a thumbnail to a wordpress post using xmlrpclib Python library?

心已入冬 提交于 2019-12-04 19:44:36
I'm trying to develope a Python's script which needs to post content to a wordpress blog, the problem is that I need to set an image as the thumbnail of the post and I don't have any idea of how to do it. This is an example of a code to post something (without thumbnail) to WP: import xmlrpclib user = 'username' passwd = 'password' server = xmlrpclib.ServerProxy('http://vizible.wordpress.com/xmlrpc.php') blog_id = 0 title = 'test title' content = 'test content, from python' blog_content = { 'title' : title, 'description' : content } categories = [{'categoryId' : 'programming', 'isPrimary' : 1}

Using gevent with python xmlrpclib

只谈情不闲聊 提交于 2019-12-04 10:00:42
Is it possible to use python's standard libs xmlrpclib with gevent? Currently i'm tried to use monkey.patch_all(), but without success. from gevent import monkey monkey.patch_all() import gevent import time import xmlrpclib from SimpleXMLRPCServer import SimpleXMLRPCServer import urllib2 def fetch(url): g = gevent.spawn(urllib2.urlopen, url) return g.get().read() def is_even(n): return n%2 == 0 def req(url): return fetch(url) server = SimpleXMLRPCServer(("localhost", 8000)) print "Listening on port 8000..." server.register_function(is_even, "is_even") server.register_function(req, "req")

How to retain cookies for xmlrpc.client in Python 3?

冷暖自知 提交于 2019-12-04 04:37:11
问题 The default Python xmlrpc.client.Transport (can be used with xmlrpc.client.ServerProxy ) does not retain cookies, which are sometimes needed for cookie based logins. For example, the following proxy, when used with the TapaTalk API (for which the login method uses cookies for authentication), will give a permission error when trying to modify posts. proxy = xmlrpc.client.ServerProxy(URL, xmlrpc.client.Transport()) There are some solutions for Python 2 on the net, but they aren't compatible

How to retain cookies for xmlrpc.client in Python 3?

不羁岁月 提交于 2019-12-01 20:47:08
The default Python xmlrpc.client.Transport (can be used with xmlrpc.client.ServerProxy ) does not retain cookies, which are sometimes needed for cookie based logins. For example, the following proxy, when used with the TapaTalk API (for which the login method uses cookies for authentication), will give a permission error when trying to modify posts. proxy = xmlrpc.client.ServerProxy(URL, xmlrpc.client.Transport()) There are some solutions for Python 2 on the net, but they aren't compatible with Python 3. How can I use a Transport that retains cookies? Existing answer from GermainZ works only

Use Python xmlrpclib with unix domain sockets?

邮差的信 提交于 2019-11-30 18:56:53
I'm trying to interact with supervisord , and I'd like to talk with it over a unix socket (it's a shared hosting environment). What I've tried so far is: import xmlrpclib server = xmlrpclib.ServerProxy('unix:///path/to/supervisor.sock/RPC2') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/xmlrpclib.py", line 1549, in __init__ raise IOError, "unsupported XML-RPC protocol" IOError: unsupported XML-RPC protocol /path/to/supervisor.sock definitely exists. URIs of the form 'unix:///path/to/supervisor.sock/RPC2' are used by supervisord , which is

Use Python xmlrpclib with unix domain sockets?

大憨熊 提交于 2019-11-30 02:21:00
问题 I'm trying to interact with supervisord , and I'd like to talk with it over a unix socket (it's a shared hosting environment). What I've tried so far is: import xmlrpclib server = xmlrpclib.ServerProxy('unix:///path/to/supervisor.sock/RPC2') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/xmlrpclib.py", line 1549, in __init__ raise IOError, "unsupported XML-RPC protocol" IOError: unsupported XML-RPC protocol /path/to/supervisor.sock