0

in py2 there was

rv = xmlrpc.pastes.newPaste(language, code, None, filename, mimetype, private)

I'm getting error : expected an object with the buffer interface

Can't find any docs about xmlrpc and py3. I found only this snippet :

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="")

but I'm still being confused about it... my version used many arguments, where can I find full description of it / fix for it ?

Thank you.

cnd
  • 32,616
  • 62
  • 183
  • 313
  • The arguments are the same as you're already using. You just have to make sure that text is `str`, not `bytes`. – Thomas K Jul 25 '11 at 12:07

2 Answers2

3

That error message usually means it's looking for str (which is Unicode in Python 3), not bytes . Like in the example, you'll need to decode the argument which is in bytes. Maybe:

rv = xmlrpc.pastes.newPaste(language, code.decode(), None, filename, mimetype, private)

But it's hard to tell what the problem is without seeing your code.

Thomas K
  • 39,200
  • 7
  • 84
  • 86
  • there are only None and private non-str elements – cnd Jul 25 '11 at 12:21
  • 1
    @nCdy: Can you replicate it with some non-private examples? Because that error is exactly what I see if `code` is bytes instead of str. – Thomas K Jul 25 '11 at 16:21
1

In Python 3. xmlrpclib has been split into two modules, xmlrpc.client and xmlrpc.server.

The docs for 3.2.1 can be found at:

http://docs.python.org/release/3.2.1/library/xmlrpc.client.html

http://docs.python.org/release/3.2.1/library/xmlrpc.server.html

agf
  • 171,228
  • 44
  • 289
  • 238
  • 1
    The snippet in the question is very much to do with xmlrpc. That's where the ServerProxy class comes from. – Thomas K Jul 25 '11 at 12:09
  • Well, it kind of does help. `output.decode()` is the sort of thing that he'll need to use to correct that error. – Thomas K Jul 25 '11 at 12:14
  • Still have no idea how to fix my trouble, but thank you for docs. – cnd Jul 25 '11 at 12:53
  • @Thomas is right, nCdy, `str` has changed in Python3 to `bytes`, and the 'string' type is `unicode`. You should try `.decode()` on any strings (which are actually `bytes`) you're passing, so that they get turned into `unicode`. – agf Jul 25 '11 at 12:58