2

I am creating a demo for mr.migrator and have run in to an annoying problem, showcased here:

# create image
proxy = xmlrpclib.ServerProxy(url) # reset
data = open('screenshot.png').read()
try:
    proxy.invokeFactory('Image', 'screenshot.png')
except xmlrpclib.ProtocolError:
    print sys.exc_info()[1]
except xmlrpclib.Fault:
    print "The id is invalid - it is already in use." # most likely
proxy = xmlrpclib.ServerProxy(url + '/screenshot.png')
proxy.setTitle('This is an image')
try:
    proxy.setImage(data) # XXX this fails
except:
    print sys.exc_info()[1]

This code should populate the image field with data from the image, but instead it fails consistently with:

<ProtocolError for admin:admin@localhost:8080/Plone/screenshot.png: 500 Internal Server Error>

Worse, this is all Zope2 says. I don't see any tracebacks or anything else that indicates a problem when running Plone in the foreground.

What's my next step? You can check out and reproduce this here:

I would do this the "normal" way, with keyword arguments passed to invokeFactory, but XML-RPC does not support them.

aclark
  • 4,345
  • 1
  • 19
  • 31

1 Answers1

2

This is most likely a special character error. The xml-rpc protocol can use any character XML allows you to use. You should try to wrap the image data in a Binary wrapper:

wrappedData = xmlrpclib.Binary(open('screenshot.png').read())

More info:

Giacomo Spettoli
  • 4,476
  • 1
  • 16
  • 24
  • Progress, now I get: TypeError: ('Could not adapt', , ) which I suspect I can work around by "marking" xmlrpclib.Binary or using another binary wrapper that blobs support? – aclark Oct 18 '11 at 00:30
  • I guess you could add an adapter from xmlrpclib.Binary to IBlobbable taking as example the one from StringIO to IBlobbable (http://svn.plone.org/svn/plone/plone.app.blob/trunk/src/plone/app/blob/adapters/stringio.py) – Giacomo Spettoli Oct 18 '11 at 00:51
  • Done: https://github.com/aclark4life/plone.app.blob/blob/master/src/plone/app/blob/adapters/xmlrpc.py – aclark Oct 19 '11 at 18:33
  • Wow...I was just thinking "ehi this should be added to the p.a.blob package because it could be usefull also for others". Very Good :) – Giacomo Spettoli Oct 19 '11 at 20:52