I am currently attempting to push html updates to a page for a user using PubNub. I want to push html code to the user (this includes links, quotes, making html necessary), and add it to the end of a table for the user.
I am currently attempting to use the api to send a message as follows:
info = pubnub.publish({
'channel' : 'myChannel',
'message' : {
'some_text' : message
}
})
Where message is:
<div class="content">Message text here.<img src="image.gif" border="0" alt="" title="laugh out loud" class="inlineimg" /></div>
My issue is that I am receiving the following message when I attempt to send a page update:
</div> is not JSON serializable
I am assuming this is occurring because I am attempting to send html code?
Any recommendations on how to fix this / better ways to do this? This is my first attempt at “pushing” messages to a webpage, so I may be implementing this all wrong.
You are attempting to send raw HTML via PubNub and running into the “JSON not Serializable” issue. Firstly, you are correct in assuming that you Can push HTML code! Hurray. Just make sure that the data you place inside the
"message"is in fact a STRING. The following types are JSON Serializable:Make sure to not send special python classes or functions. These will not serialize. String content can include any UTF-8 character single-byte and multi-byte.
Use this Python for the
"message":