问题
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