Skip to content

Instantly share code, notes, and snippets.

@fvdbosch
Last active June 26, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fvdbosch/24671484c7233fec903c9217497b0312 to your computer and use it in GitHub Desktop.
Save fvdbosch/24671484c7233fec903c9217497b0312 to your computer and use it in GitHub Desktop.
Example for REST calls in Python
#!/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