Plugin HTTP Connection strange response??

Python and python framework
Post Reply
febalci
Posts: 306
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Plugin HTTP Connection strange response??

Post by febalci » Wednesday 10 January 2018 17:10

Using Beta 3.8789.
I am trying to write a Plex Status Plugin. The first thing i tried was to establish an HTTP connection to Plex Server.

Code: Select all

self.plexConn = Domoticz.Connection(Name="PlexConn", Transport="TCP/IP", Protocol="HTTP", Address=Parameters["Address"], Port=Parameters["Port"])
And try to catch XML response from /status/sessions page which gives:

Code: Select all

<MediaContainer size="0">
</MediaContainer>
in return when there's no activity.

Code: Select all

statusData = { 'Verb' : 'GET',
                         'URL'  : '/status/sessions',
                         'Headers' : { 'Content-Type': 'text/xml; charset=utf-8', \
                                       'Connection': 'keep-alive', \
                                       'Accept': 'Content-Type: text/html; charset=UTF-8', \
                                       'Host': Parameters["Address"]+":"+Parameters["Port"], \
                                       'User-Agent':'Domoticz/1.0' }
                       }
                self.plexConn.Send(statusData)
gets back something like:

Code: Select all

2018-01-10 17:58:13.100 (Plex) Received 263 bytes of data:
2018-01-10 17:58:13.101 (Plex) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 43 6f 6e HTTP/1.1.200.OK..Con
2018-01-10 17:58:13.101 (Plex) 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 78 6d 6c 3b tent-Type:.text/xml;
2018-01-10 17:58:13.101 (Plex) 63 68 61 72 73 65 74 3d 75 74 66 2d 38 0d 0a 43 6f 6e 74 65 charset=utf-8..Conte
2018-01-10 17:58:13.101 (Plex) 6e 74 2d 4c 65 6e 67 74 68 3a 20 38 33 0d 0a 43 6f 6e 6e 65 nt-Length:.83..Conne
2018-01-10 17:58:13.101 (Plex) 63 74 69 6f 6e 3a 20 63 6c 6f 73 65 0d 0a 58 2d 50 6c 65 78 ction:.close..X-Plex
2018-01-10 17:58:13.101 (Plex) 2d 50 72 6f 74 6f 63 6f 6c 3a 20 31 2e 30 0d 0a 43 61 63 68 -Protocol:.1.0..Cach
2018-01-10 17:58:13.101 (Plex) 65 2d 43 6f 6e 74 72 6f 6c 3a 20 6e 6f 2d 63 61 63 68 65 0d e-Control:.no-cache.
2018-01-10 17:58:13.101 (Plex) 0a 44 61 74 65 3a 20 57 65 64 2c 20 31 30 20 4a 61 6e 20 32 .Date:.Wed,.10.Jan.2
2018-01-10 17:58:13.101 (Plex) 30 31 38 20 31 34 3a 35 38 3a 31 32 20 47 4d 54 0d 0a 0d 0a 018.14:58:12.GMT....
2018-01-10 17:58:13.101 (Plex) 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20
2018-01-10 17:58:13.101 (Plex) 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 3f 3e 0a 3c encoding="UTF-8"?>.<
2018-01-10 17:58:13.101 (Plex) 4d 65 64 69 61 43 6f 6e 74 61 69 6e 65 72 20 73 69 7a 65 3d MediaContainer.size=
2018-01-10 17:58:13.101 (Plex) 22 30 22 3e 0a 3c 2f 4d 65 64 69 61 43 6f 6e 74 61 69 6e 65 "0">.
2018-01-10 17:58:13.102 (Plex) 72 3e 0a .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. r>.
2018-01-10 17:58:13.102 (Plex) Calling message handler 'onMessage'.
2018-01-10 17:58:13.102 (Plex) HTTP Details (3):
2018-01-10 17:58:13.102 (Plex) --->'Status':'200'
2018-01-10 17:58:13.102 (Plex) --->'Headers (6):
2018-01-10 17:58:13.102 (Plex) ------->'Content-Type':'text/xml;charset=utf-8'
2018-01-10 17:58:13.102 (Plex) ------->'Content-Length':'83'
2018-01-10 17:58:13.102 (Plex) ------->'Connection':'close'
2018-01-10 17:58:13.103 (Plex) ------->'X-Plex-Protocol':'1.0'
2018-01-10 17:58:13.103 (Plex) ------->'Cache-Control':'no-cache'
2018-01-10 17:58:13.103 (Plex) ------->'Date':'Wed, 10 Jan 2018 14:58:12 GMT'
2018-01-10 17:58:13.103 (Plex) --->'Data':'b'\n\n\n'' 
Please note that the first and the last line of xml is valid for hex but missing for ascii, so the data received is only a 'b'\n\n\n''.

So i tried the same thing with 'None' connection instead of 'HTTP'. Still the same:

Code: Select all

2018-01-10 17:49:04.626 PluginSystem: Restarting I/O service thread.
2018-01-10 17:49:04.626 (Plex) Received 263 bytes of data:
2018-01-10 17:49:04.626 (Plex) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 43 6f 6e HTTP/1.1.200.OK..Con
2018-01-10 17:49:04.626 (Plex) 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 78 6d 6c 3b tent-Type:.text/xml;
2018-01-10 17:49:04.626 (Plex) 63 68 61 72 73 65 74 3d 75 74 66 2d 38 0d 0a 43 6f 6e 74 65 charset=utf-8..Conte
2018-01-10 17:49:04.626 (Plex) 6e 74 2d 4c 65 6e 67 74 68 3a 20 38 33 0d 0a 43 6f 6e 6e 65 nt-Length:.83..Conne
2018-01-10 17:49:04.626 (Plex) 63 74 69 6f 6e 3a 20 63 6c 6f 73 65 0d 0a 58 2d 50 6c 65 78 ction:.close..X-Plex
2018-01-10 17:49:04.626 (Plex) 2d 50 72 6f 74 6f 63 6f 6c 3a 20 31 2e 30 0d 0a 43 61 63 68 -Protocol:.1.0..Cach
2018-01-10 17:49:04.626 (Plex) 65 2d 43 6f 6e 74 72 6f 6c 3a 20 6e 6f 2d 63 61 63 68 65 0d e-Control:.no-cache.
2018-01-10 17:49:04.626 (Plex) 0a 44 61 74 65 3a 20 57 65 64 2c 20 31 30 20 4a 61 6e 20 32 .Date:.Wed,.10.Jan.2
2018-01-10 17:49:04.627 (Plex) 30 31 38 20 31 34 3a 34 39 3a 30 33 20 47 4d 54 0d 0a 0d 0a 018.14:49:03.GMT....
2018-01-10 17:49:04.627 (Plex) 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20
2018-01-10 17:49:04.627 (Plex) 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 3f 3e 0a 3c encoding="UTF-8"?>.<
2018-01-10 17:49:04.627 (Plex) 4d 65 64 69 61 43 6f 6e 74 61 69 6e 65 72 20 73 69 7a 65 3d MediaContainer.size=
2018-01-10 17:49:04.627 (Plex) 22 30 22 3e 0a 3c 2f 4d 65 64 69 61 43 6f 6e 74 61 69 6e 65 "0">.
2018-01-10 17:49:04.628 (Plex) 72 3e 0a .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. r>.
2018-01-10 17:49:04.628 (Plex) Calling message handler 'onMessage'.
2018-01-10 17:49:04.630 (Plex) onMessage called with Data: 'HTTP/1.1 200 OK
Content-Type: text/xml;charset=utf-8
Content-Length: 83
Connection: close
X-Plex-Protocol: 1.0
Cache-Control: no-cache
Date: Wed, 10 Jan 2018 14:49:03 GMT




'
So, the plugin framework simply discards "<?xml version="1.0" part and "</MediaContaine" and also converting the response to str, it loses all!
@Dnpwwo, is this a bug?
What am i doing wrong???

User avatar
Xorfor
Posts: 83
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Plugin HTTP Connection strange response??

Post by Xorfor » Wednesday 10 January 2018 22:38

Last weekend I experienced the same. The XML I got was also corrupted: the first part was missing. In my case is was a large XML response (more than 1000 lines in the browser) and I was missing the first half :(

@febalci:

The log is misleading, because you don't see the XML tags, because these are treated as HTML tags in you browser!

febalci
Posts: 306
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Plugin HTTP Connection strange response??

Post by febalci » Thursday 11 January 2018 9:24

Xorfor wrote:
Wednesday 10 January 2018 22:38
Last weekend I experienced the same. The XML I got was also corrupted: the first part was missing.
This was just a test for a simple xml page. As you said, if i go for a longer XML response, i lose the whole first part too. Changed from beta 3.8789 to 8798. Still the same.

Also i don't believe the log is misleading because i also tried the connection with TCP/IP-None, instead of TCP/IP-HTTP. This is supposed the bring all page without any interference to html tags, the page as it is. Still missing the same parts. I do not have this problem with JSON requests, only XML. I believe this might be a bug.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests