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

mrblue
  • 807
  • 2
  • 12
  • 24
  • 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. – Lennart Regebro Jan 02 '11 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. – mrblue Jan 03 '11 at 02:22

1 Answers1

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.

Jonathan Eunice
  • 21,653
  • 6
  • 75
  • 77
  • 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 objects – mrblue Jan 06 '11 at 20:09