4

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

2
  • Does wordpress XMLRPC supoprt what you want? Does the Python library you are using support what you want? If it does, the documentation should tell you how. Commented Jan 2, 2011 at 12:33
  • I think yes, because I've tried the desktop application, which based on XMLRPC, and it could post HTML perfectly. I think the problem is on the encode/decode of the data from Python to send out, but still not figuring out. Thanks. Commented Jan 3, 2011 at 2:22

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Jonathan, I tried BeatifulSoup to encode them before sending out and it seems to work but not stable, some times I got an error like this: TypeError: cannot marshal <class 'BeautifulSoup.NavigableString'> objects

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.