简体   繁体   English

使用Python创建一个新的wordpress帖子(xmlrpc或wordpress_xmlrpc)

[英]Create a new wordpress post using Python (xmlrpc or wordpress_xmlrpc)

I'm trying to automate some blog posting so that I can automatically post the contents of a text file onto a wordpress site I use for school. 我正在尝试自动发布一些博客文章,以便我可以自动将文本文件的内容发布到我用于学校的wordpress网站上。 The site is wordpress version 4.1.1 该网站是wordpress版本4.1.1

So far I have tried using the wordpress_xmlrpc method and have been having some difficulties. 到目前为止,我已经尝试使用wordpress_xmlrpc方法并且遇到了一些困难。

Here's an example of the code I've been trying to use: 这是我一直尝试使用的代码示例:

from wordpress_xmlrpc import Client
from wordpress_xmlrpc.methods import posts

client = Client(...)
posts = client.call(posts.GetPosts())

page = WordPressPage()
page.title = 'About Me'
page.content = 'I am an aspiring WordPress and Python developer.'
page.post_status = 'publish'
page.id = client.call(posts.NewPost(page))

page.content = 'I am a WordPress and Python developer.'
client.call(posts.EditPost(page.id, page))

I don't particularly need anything complicated, I just want to get a simple python script working that creates a simple post on my school's blog. 我并不特别需要任何复杂的东西,我只是希望得到一个简单的python脚本,在我学校的博客上创建一个简单的帖子。

Any help with why my examples aren't working, or any other examples that could work is greatly appreciated. 任何有关我的示例无法正常工作的帮助,或任何其他可行的示例都非常感谢。

Thanks! 谢谢!

Your issue is with client.call(posts.getPosts()) ...Watch the case! 你的问题是client.call(posts.getPosts()) ...观看案例! It should be: client.call(posts.GetPosts()) , with a capital G . 它应该是: client.call(posts.GetPosts()) ,大写client.call(posts.GetPosts()) G

The error clues you into this: 错误提示你:

AttributeError: 'module' object has no attribute 'getPosts' AttributeError:'module'对象没有属性'getPosts'

This would be a reminder to check the methods of posts . 这将提醒我们检查posts方法 A quick search will expose the simple typo. 快速搜索将揭示简单的拼写错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM