Bad interaction between Zope2 XML-RPC and AT Image mutator?

▼魔方 西西 提交于 2020-01-15 07:20:42

问题


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:

  • https://github.com/aclark4life/xmlrpc_setimage_wtf

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


回答1:


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:

  • http://effbot.org/zone/xmlrpc-ascii.htm
  • http://docs.python.org/library/xmlrpclib.html


来源:https://stackoverflow.com/questions/7800801/bad-interaction-between-zope2-xml-rpc-and-at-image-mutator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!