Centova Technologies Forum

Centova Cast v2 => Technical discussion => Topic started by: SCIFI.radio on March 04, 2012, 05:11:11 pm

Title: API Calls with Python
Post by: SCIFI.radio on March 04, 2012, 05:11:11 pm
Hi, everybody, yes, I'm bumping my head on something that should be simple.

Is anybody using Python to talk to the API, and if so, could somebody posted a short example of Python code that sends a command packet to the Centova api.php that actually works?  No matter how I do mine, I always get the error packet back that says "XML root tag not found".  (Obviously, I am using a root tag.)

I think I'd do better with a code sample.

- Gene
Title: Re: API Calls with Python
Post by: SCIFI.radio on March 06, 2012, 10:23:09 am
Okay - then ANY other language.  I know a bunch of them, I just need some help getting over this hurdle.

My XML packet:

<?xml version "1.0" encoding="UTF-8"?>
<centovacast>
<request class="system" method="info">
<password>mypassword</password>
<username>myusername</username>
</request>
</centovacast>


What I get back:

<?xml version="1.0" encoding="UTF-8"?><centovacast version="2.2.4" host="mycentovainstallationurl.com"><response type="error"><message>XML root tag not found.</message></response></centovacast>
Title: Re: API Calls with Python
Post by: Centova - Steve B. on March 10, 2012, 10:40:30 pm
Looks like your Python code is mangling the XML markup somehow before posting it to the server.  I don't know Python but Googling how to fetch an URL yielded an example that I was easily able to modify to work with Centova Cast:

Code: [Select]
import urllib
params = '<?xml version="1.0" encoding="UTF-8"?>\
<centovacast>\
<request class="system" method="version">\
<password>xxx</password>\
<username>admin</username>\
</request>\
</centovacast>';
f = urllib.urlopen("http://cc.local/api.php", params)
print f.read()

Running the above script yields the expected response for the system.version method:

Code: [Select]
<?xml version="1.0" encoding="UTF-8"?><centovacast version="2.2.6" host="cc.local"><response type="success"><message>Centova Cast v2.2.6</message><data><row><field name="version">2.2.6</field><field name="loadavg1">0.00</field><field name="loadavg5">0.00</field><field name="loadavg15">0.00</field><field name="uptime">4606995.36</field><field name="os">Debian Linux</field><field name="osversion">2.6.26-2-xen-amd64</field><field name="accounts">15</field><field name="activeaccounts">13</field></row></data></response></centovacast>

As I said I'm not a Python guy so I can't offer any advice beyond telling you that it's pretty much guaranteed to be an issue with your code... sorry.
Title: Re: API Calls with Python
Post by: SCIFI.radio on March 12, 2012, 08:37:40 am
The guy gives me precisely what I need, then apologizes.  Yeesh.   8)
Title: Re: API Calls with Python
Post by: SCIFI.radio on April 10, 2012, 08:55:09 am
I can now handle episodic shows without having to manually schedule a new show for every episode (instead replacing the contents of one scheduled event with new contents every week from a list) and weekly prerecorded shows that are uploaded fresh each week without having to manually replace the scheduled show's contents every time there's a new upload.

The API works like a charm, and is dead simple to use.  Very happy.