Page MenuHomec4science

restful_client.py
No OneTemporary

File Metadata

Created
Mon, Jun 10, 14:37

restful_client.py

from conf_ems import *
import bmsinterface.auxiliary.requests.api as requests
import sys
def get_bms_info(resource_type='room', resource_id=1):
"""Returns the info for the given ID according to the docs in openBMS"""
geturl = 'http://{0}:{1}/API/{2}/{3}'.format(OPENBMS_IP, OPENBMS_PORT, resource_type, resource_id)
r = requests.get(geturl)
# always check the return status code!
if r.status_code == 200: # Otherwise it means openBMS doesnt work
request_result = r.json()
return request_result
elif r.status_code == 404 and r.content: # Server replied but not found the midid
print('Failed to find in openBMS the {0}: {1}'.format(resource_type, resource_id))
sys.exit()
else:
print('Failed to connect to {0}:{1}, is openBMS running?'.format(OPENBMS_IP,OPENBMS_PORT))
sys.exit()
print(get_bms_info())

Event Timeline