mrblue
mrblue

Reputation: 819

Post HTML data via XMLRPC in Python?

I am writing a small script by Python to connect and post content to my WordPress blog. It's pretty straightforward with https://github.com/maxcutler/python-wordpress-xmlrpc

However, when i tried to input a HTML data, for example:

<b>Hello</b>

It appears exactly in the WordPress post (I watch it from the visual editor, and I need to re-format it by copying the data to HTML mode to have the expected result.

What should I do with my python script ?

Thank you very much

Upvotes: 4

Views: 1264

Answers (1)

Jonathan Eunice
Jonathan Eunice

Reputation: 22443

Could the HTML data you are uploading already have its angle brackets escaped into HTML entities? I.e. < becomes &lt; while > becomes &gt;

This would lead to the behavior you describe. The visual editor would show what looks like raw HTML, not the result of rendering HTML.

To fix, either (i) prevent that encoding, or (ii) the quick and dirty approach, do a search and replace on the HTML before handing to your API. Something along the lines of:

html = html.replace('&lt;', '<')
html = html.replace('&gt;', '>') 

should do the trick.

Upvotes: 1

Related Questions