简体   繁体   中英

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. The site is wordpress version 4.1.1

So far I have tried using the wordpress_xmlrpc method and have been having some difficulties.

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.

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! It should be: client.call(posts.GetPosts()) , with a capital G .

The error clues you into this:

AttributeError: 'module' object has no attribute 'getPosts'

This would be a reminder to check the methods of posts . A quick search will expose the simple typo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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