Bad interaction between Zope2 XML-RPC and AT Image

2019-07-17 17:28发布

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.

1条回答
何必那么认真
2楼-- · 2019-07-17 18:01

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:

查看更多
登录 后发表回答