-
-
Save fvdbosch/24671484c7233fec903c9217497b0312 to your computer and use it in GitHub Desktop.
Example for REST calls in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import requests | |
def restcmd(command): | |
# url of the REST API, player command passed via function | |
url = "http://justboom.local/api/v1/commands/?cmd=" + command | |
try: | |
# make the request and get teh response | |
response = requests.get(url) | |
if(response.ok): | |
# do something if the response is ok | |
print("response ok") | |
else: | |
# do something if the response is not ok | |
print("response not ok") | |
# do something if a connection error occurs | |
except requests.ConnectionError as e: | |
print("connection error") | |
restcmd("play") # play, stop, pause, previous, next, volume |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment