xmlrpc newPaste - 期待一个带缓冲区接口的对象
在Python 2中,有这样的代码:
rv = xmlrpc.pastes.newPaste(language, code, None, filename, mimetype, private)
我遇到了一个错误:期待一个具有缓冲区接口的对象。
我找不到关于xmlrpc和Python 3的任何文档。我只找到这一小段代码:
p1 = subprocess.Popen(['gpg','--clearsign'], stdin = subprocess.PIPE, stdout=subprocess.PIPE)
p1.stdin.write(bytes(input, 'UTF8'))
output = p1.communicate()[0]
s = ServerProxy('http://paste.pocoo.org/xmlrpc/')
pasteid = s.pastes.newPaste('text',output.decode())
print ("http://paste.pocoo.org/raw/",pasteid,"/", sep="")
但我还是搞不清楚……我的版本用了很多参数,我在哪里可以找到它的完整描述或解决办法呢?
谢谢。
2 个回答
1
在Python 3中,xmlrpclib
这个模块被拆分成了两个新的模块,分别是xmlrpc.client
和xmlrpc.server
。
关于3.2.1版本的文档可以在这里找到:
http://docs.python.org/release/3.2.1/library/xmlrpc.client.html
http://docs.python.org/release/3.2.1/library/xmlrpc.server.html
3
这个错误信息通常意味着它在寻找的是 str
(在Python 3中是Unicode字符串),而不是 bytes
(字节)。就像例子中那样,你需要把传入的参数从字节格式解码成字符串格式。可能需要这样做:
rv = xmlrpc.pastes.newPaste(language, code.decode(), None, filename, mimetype, private)
不过,如果不看到你的代码,很难判断具体问题出在哪里。