TobKra96 / music_led_strip_control

Audio visualization for LED strips in real-time with web interface on a raspberry pi.
https://tobkra96.github.io/music_led_strip_control/
MIT License
297 stars 64 forks source link

[newbie question] How come this MLSC API code doesn't work? #154

Closed 42Willow closed 2 years ago

42Willow commented 2 years ago
import requests

query = {
    'device': 'device_0',
    'effect': "effect_single"
}
requests.post('http://192.168.1.90/api/effect/active', params = query)

I get a 403 response which according to the documentation means input data are wrong. Does anyone know how to solve this?

Teraskull commented 2 years ago

Hi @Burraby,

First, it's because you did not specify the default port in the URL (8080, or a different one if you changed it). Second, you have to pass the query as json, not params. The following code should work:

import requests

query = {
    "device": "device_0",
    "effect": "effect_single"
}
r = requests.post('http://192.168.1.90:8080/api/effect/active', json=query)
print(r)

This should print <Response [200]>.

42Willow commented 2 years ago

Hi @Burraby,

First, it's because you did not specify the default port in the URL (8080, or a different one if you changed it). Second, you have to pass the query as json, not params. The following code should work:

import requests

query = {
    "device": "device_0",
    "effect": "effect_single"
}
r = requests.post('http://192.168.1.90:8080/api/effect/active', json=query)
print(r)

This should print <Response [200]>.

Thank you for the quick reply, it works!