[Python] RPC connect - Errno 104
Added by Peter Iwanowitsch almost 13 years ago
Hi Folks,
playing around with Python to control the TVHeadend-Server.
It's told that the server uses RPC communication protokoll.
I tried for example this (Pythoncode, xmlrpclib provides clientaccess to RPC Servers):
from xmlrpclib import ServerProxy
server = ServerProxy("http://localhost:9982", verbose = True)
server.getSysTime()
and get "socket.error: [Errno 104] Connection reset by peer"
Doesn't matter which function I try - server.hello(0,"test","0.1",0,"root","root") or other calls will allways raise this error.
Im running LMDE, hts-tvheadend via repository lonleycoder .. I can login via http://localhost:9981, User/PW "root" ...
Any ideas ?
Greetz
LastCoder
Replies (14)
RE: [Python] RPC connect - Errno 104 - Added by Peter Iwanowitsch almost 13 years ago
btw. the python client sends the following to the server:
<methodCall>
<methodName>getSysTime</methodName>
<params></params>
</methodCall>
At least the server object seems to get created .. if I change something for the server constructor I get 404 Errors ..
So long
LastCoder
RE: [Python] RPC connect - Errno 104 - Added by Peter Iwanowitsch almost 13 years ago
Syslog of the webinterface shows:
htsp: Got connection from 127.0.0.1
htsp: 127.0.0.1: Disconnected
at the same time ...
RE: [Python] RPC connect - Errno 104 - Added by Peter Iwanowitsch almost 13 years ago
hm .. seems that you don't use XML format for RPC commands - htsmsg.c from tvheadend and htsp.c from showtime seem to build a "binary" / proprietary structure ..
.. is the disconnection the usal behavior if nothing "useful" is sended by the client ?
.. could you please paste an example structure of a RPC message to tvheadend (means: a real world dump) so I could get some inspiration to implement it with python ? I'm not that familiar with C to get it only from the C source ..
Thx
LastCoder
RE: [Python] RPC connect - Errno 104 - Added by Hein Rigolo almost 13 years ago
I assume you already looked at this page:
http://www.lonelycoder.com/redmine/projects/tvheadend/wiki/Htsp
There you can find a description on how the HTPS protocol works and what is exactly in each call.
Hein
btw, Welcome to Tvheadend
RE: [Python] RPC connect - Errno 104 - Added by Peter Iwanowitsch almost 13 years ago
Hi Hein,
self-evident .. but this info page doesn't for example clearly explain that there is a field that has to be filled with the key "method" (it's obvious that there has to be such an key but it's not obvious that is called "method" ;-) that has to be filled with the identifier of the called method .. this isn't self explaining as you can see for example how the XML-RPC modul of python handles requests. Unfortunately there is even no info about the order .. for example htsp.c of showtime adds "method"->"hello" after the other fields ..
Notwithstanding the above, I need a binary dump of a regular tvheadend RPC request to compare it (its byte structure) to the request that the python ("struct.pack" and "socket.send") invokes .. Why ? It's seems, that tvheadend server every kind of irregular request simply denies with "connection reset" and without giving further information why or what went wrong .. so I'm playing around with different kinds of RPC request without success always getting the little expressive syslog "disconnected" ... and if I invoke a socket read order to get a RPC result from the server there simply happens nothing - my scripts waits without end ?!?
If I ever get it running I'll post a short tutorial ;-) .. btw. I read that showtime supports live tv with tvheadend - didn't find a feature list - teletext ? Channel & EPG information ? PVR ?
So long
LastCoder
RE: [Python] RPC connect - Errno 104 - Added by Peter Iwanowitsch almost 13 years ago
.. again me ;-) .. I created an example "hello" htsmsg in c and dumped it .. does the client really send the entire memory representation of the htsmsg struct to the server ??? In that case it's nearly impossible to communicate with TVHeadend-Server with any other language than c/c++ .. there is simply no way in simulating a complete memory struct in native python or php; I guess even with java it would be problematic .. I really hope that the RPC communication is limited to the keywords and values ?!? Best way would be of course using XML-RPC - seems that you have with htsmsg_xml.c functions for converting HTSMSGs to/from XML - are they used for RPC communication ??
So long
LastCoder
RE: [Python] RPC connect - Errno 104 - Added by Sébastien Aubry over 12 years ago
Hello,
I get the same errors. Did you manage to get anywhere further in communicating with the TVH server using (XML-)RPC?
Is there any way to dump the RPC strings passed to the TVH server when using the web interface?
Thanks
RE: [Python] RPC connect - Errno 104 - Added by Adam Sutton over 12 years ago
Guys,
currently HTSP is the only way to communicate with TVHeadend. We have plans to add a full JSON interface (there is a limited one as used by the webui), but they are just that at the moment plans.
As for python being unable to communicate binary protocols, that's ridiculous (sorry if that's harsh). I have written python apps to communicate, using binary protocols, with numerous different systems.
Here are two ways of doing it, there are many more:
1. Build the messages by hand, a python string is a binary string (its not NUL terminated like C, etc..) And ultimately this is how you send data packets.
2. Use something like ctypes to help do the conversion from object struct(ure) in python to binary string. It has structure processing code.
If you're still interested in communicating with TVH from python via HTSP give me a shout. I'm pushed for time but I'm sure I could provide enough of an example to get you going.
Adam
RE: [Python] RPC connect - Errno 104 - Added by Sébastien Aubry over 12 years ago
Hello Adam,
Yes, an example would be useful.
You are right, it looks like we only want to send C binary data through HTTP. XML-RPC is not the right way to go at this time :-)
First try:
from ctypes import * s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('localhost', 9982))
Log:
Aug 07 12:49:53 htsp: Got connection from 127.0.0.1
Then:
s.send(c_char_p('hello htspversion 2 clientname test clientversion 0.1\n'))
Log:
Aug 07 12:49:48 htsp: 127.0.0.1: Disconnected
After looking at the htsmsg.c and htsp.c files, I am not sure if we are supposed to send/receive a standard string or a serialized structure.
RE: [Python] RPC connect - Errno 104 - Added by Sébastien Aubry over 12 years ago
Now found the deserialization code inside the htsmsg_binary_des0 method of htsmsg.c
Creating such messages looks quite complicated but it can certainly be done!
RE: [Python] RPC connect - Errno 104 - Added by Sébastien Aubry over 12 years ago
I have been through the Htsmsgbinary wiki page .
I do not understand the following: "The root message must always be of type map". Does this mean that we have to include the "Lenght" and "Body" field names inside the message? I cannot find them in the code so I assume that this message is of type list, isn't it?
Now trying to send things like:
s.send(c_char_p('\x00\x00\x01\x02\03\00\00\00\00\0cgetDiskspace'))
without success, but still hoping!
RE: [Python] RPC connect - Errno 104 - Added by Adam Sutton over 12 years ago
You'll have to forgive me this is very rough and ready and I've only tested hello and response.
It's not the way I'd do it if I was actually thinking about things, but its essentially a very rough translation of htsmsg_binary.c.
The example script create's a "hello" message, sends it and outputs the response. Any more than that you'll need to do yourself
Regards
Adam
P.S.
If I get the time I might tidy the code up and provide a proper lib with TVH, to do proper wrapping of the connection etc.., if people think it might be of use.
RE: [Python] RPC connect - Errno 104 - Added by Sébastien Aubry over 12 years ago
Thank you very much. First thing I will do is improve my autodelete script to perform the deletions through the TVH server.
RE: [Python] RPC connect - Errno 104 - Added by Adam Sutton over 12 years ago
Slight update, I tidied stuff up a "bit". But also there was a bug in the int deserialize.
Adam
Note: the authentication is completely untested, my server is all anon access and couldn't be arsed to set a password