Page 1 of 1

python plugin: logging special characters

Posted: Friday 04 August 2017 18:54
by elgringo
I have a device which sends XML of HTTP. For example:

Code: Select all

<?xml version="1.0" encoding="utf-8"?><envelope><HDCPError>200</HDCPError><HDCPErrorDetail>OK</HDCPErrorDetail><session>479877994</session></envelope>
This message is stored in a variable eg 'txt'

When executing:

Code: Select all

 
Domoticz.Log(txt)
It appear in the logging as:

Code: Select all

2017-08-04 18:51:47.880 (TV) 200OK479877994
When adding additional escape chars ( Domoticz.Log(re.escape(txt)) ):

Code: Select all

2017-08-04 18:36:27.041 (TV)  \<\?xml\ version\=\"1\.0\"\ encoding\=\"utf\-8\"\?\>\\200\<\/HDCPError\>\OK\<\/HDCPErrorDetail\>\479877994\<\/session\>\<\/envelope\>
How a I log the original message?

Re: python plugin: logging special characters

Posted: Friday 04 August 2017 21:16
by mivo
Hi,

try this - should be standard Python modules:
https://wiki.python.org/moin/EscapingHtml

Re: python plugin: logging special characters

Posted: Saturday 05 August 2017 11:31
by elgringo
Thanks! That function did the trick :)

Re: python plugin: logging special characters

Posted: Tuesday 08 August 2017 14:19
by elgringo
The text is intrepeted as HTML, so the XML tags disappear. Escaping HTML will replace these charaacters: See https://wiki.python.org/moin/EscapingHtml