Sending post inludes non-latin characters with python

I have a WordPress website and I want to send some specific posts using python. When my posts includes no non-latin character, I have no problem, I can easily publish them.

However, when I use characters like ‘ğ’ or ‘ş’ in my post, it gives me a parse error. not well formed error. I have to use iso-8859-9 encoding due to language of my site and I couldn’t solve this problem no matter what I’ve tried.

Read More

Here is my code:

# -*- coding: iso-8859-9 -*-
from wordpress_xmlrpc import Client
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc import WordPressPost


wp = Client('http://websiteurl/xmlrpc.php', 'username', 'pass')
#posts = wp.call(posts.GetPosts())
#print posts[0]

data="Güneş doğudan doğar"

post = WordPressPost()
post.title = 'My Post Title'
post.content = data
post.id = wp.call(posts.NewPost(post))

post.post_status = 'publish'
wp.call(posts.EditPost(post.id, post))

Related posts

Leave a Reply

1 comment

  1. data is already encoded as iso-8859-9, so you’ll want to decode() it in order to pass it through to WordPress. The problem line is post.content = data. You’ll want to change it to:

    post.content = data.decode("iso-8859-9")