How do I send a PUT and GET Json

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

How do I send a PUT and GET Json

Post by Mastiff » Sun Oct 08, 2017 5:05 pm

I want to control a program via it's API (TuneBlade, which sends AirPlay streams to receivers) using PUT requests, and the format is JSON, like this:

Code: Select all

http://192.168.0.1:56569/devices/{ID}
{
“Status”: “Connect”
}
The ID is the AirPlay ID, which usually contains a name and a MAC address. Can somebody please tell me how I can do that in Python script?

User avatar
yokel22
Experienced User
Posts: 265
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: How do I send a PUT and GET Json

Post by yokel22 » Mon Oct 09, 2017 12:23 am

You can do it like this from script, but will throw an error on eg 5.0 beta 4(other versions should work fine). I'd suggest you check out boolean123's httpRequest plugin here instead:viewtopic.php?f=9&t=9780

A quick question though, does tuneblade only support system audio, or can it use iTunes too? I'm looking for something that i can just toggle my airplay zones on/off.

Code: Select all

import requests
import json
id = 'your id'
url = 'http://192.168.0.1:56569/devices/' + id
payload = { 'Status': 'Connect'  }
headers = {'content-type': 'application/json'}
putRequest = requests.put(url, data=json.dumps(payload), headers=headers)
print putRequest

Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: How do I send a PUT and GET Json

Post by Mastiff » Mon Oct 09, 2017 7:16 am

Thanks, I'll try that! And no, Tuneblade is a program that sends any audio from the chosen audio card (I use kX Drivers to get three virtual cards from one Soundblaster Audigy) to one or more AirPlay receivers, and it's the stream it sends out that can be stopped in this way, it does not control the receiver as far as I know. But you can look at the FAQ here: http://www.tuneblade.com/support/faqs.html

Post Reply