使用xmlrpc库将WordPress文章状态设置为已发布
我正在尝试用Python通过xmlrpc库发布帖子。问题出在帖子状态上:它被设置为“未来发布”,但应该是“已发布”。这是我代码的一部分:
status_draft = 0
status_published = 1
server = xmlrpclib.ServerProxy(wp_url)
title = titles.encode("utf-8")
content = text.encode("utf-8")
date_created = xmlrpclib.DateTime(datetime.datetime.today())
categories = ["News"]
tags = []
data = {'title': title, 'description': content, 'dateCreated': date_created, 'categories': categories, 'mt_keywords': tags}
post_id = server.metaWeblog.newPost(wp_blogid, wp_username, wp_password, data, status_published)
我的WordPress版本是3.5.1,Python版本是2.7。
我该如何解决这个问题呢?
1 个回答
0
我发现问题确实出在 dateCreated 上。解决这个问题的方法是把 date_created 的时间减去一个随机的时间值。