我想使用Python & XML-RPC在现有的Wordpress帖子中添加一个'enclosure‘自定义字段。
我的代码如下所示:
def add_enclosure(server, post_id, enclosure):
post_data = server.metaWeblog.getPost(post_id, username, password)
custom_fields = post_data['custom_fields']
new_id = max([int(field['id']) for field in custom_fields]) + 1
custom_fields.append({'id': "%s" % (new_id), 'key': 'enclosure', \
'value': "%s\n%s\n%s" % \
(enclosure['url'], enclosure['length'], enclosure['type'])})
server.metaWeblog.editPost(post_id, username, password, \
{'custom_fields': custom_fields})但我得到以下错误:
xmlrpclib.Fault: <Fault 500: 'Sorry, your entry could not be edited. Something wrong happened.'>我做错了什么?
发布于 2011-02-09 19:03:39
自定义字段是一组键/值对,如下所示:
"custom_fields" = (
{key = city; value = Sacramento; },
{key = city; value = Sandy; }
)尝试使用metaWeblog.getPost为已经具有自定义字段的帖子获取帖子数据,您将看到它们的样子。
https://stackoverflow.com/questions/2419768
复制相似问题