python plugin: logging special characters

Python and python framework

Moderator: leecollings

Post Reply
elgringo
Posts: 96
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

python plugin: logging special characters

Post 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?
mivo
Posts: 80
Joined: Friday 21 April 2017 8:58
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Czechia
Contact:

Re: python plugin: logging special characters

Post by mivo »

Hi,

try this - should be standard Python modules:
https://wiki.python.org/moin/EscapingHtml
My toys:
Raspberry Pi 3 + UPS PIco HV3.0 A Stack
Minibian (Raspbian Jessie) + Domoticz beta
RFLink 433 Gateway, 1wire DS18B20 temp sensors (GPIO)
RaZberry module + 2x Comet Z-Wave + Z-wave socket
---
Plugins: WeMo Switch, UPS PIco HV3.0A on GitHub
elgringo
Posts: 96
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

Re: python plugin: logging special characters

Post by elgringo »

Thanks! That function did the trick :)
elgringo
Posts: 96
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: Left
Contact:

Re: python plugin: logging special characters

Post 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
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest