Skip to content

Instantly share code, notes, and snippets.

@jfinstrom
Created September 10, 2014 16:29
Show Gist options
  • Save jfinstrom/97c4d151c259d9d26d28 to your computer and use it in GitHub Desktop.
Save jfinstrom/97c4d151c259d9d26d28 to your computer and use it in GitHub Desktop.
Snippit I use to poke around on the Asterisk ARI this changes based on endpoint and data model...
#!/usr/bin/env python
import requests
from requests.auth import HTTPBasicAuth
IPADD='192.168.0.32:8088/ari/'
ENDPOINT = 'events'
ARIUSER=''
ARIPASS=''
r = requests.get('http://%s%s' % (IPADD,ENDPOINT),auth=HTTPBasicAuth(ARIUSER,ARIPASS))
results = r.text
#results = r.json()
print results
#for r in results:
#print "Device: %s Status is %s" % (r['resource'],r['state'])
@semerkin
Copy link

semerkin commented Sep 26, 2016

import requests
import json
import sys

import logging
logging.basicConfig(level=logging.DEBUG)

try:
    r = requests.get('http://192.168.10.25:8088/ari/endpoints', auth=('hey', 'user'))
except requests.exceptions.ConnectionError:
    print '\nConnection error !'
    sys.exit(13)
print r.status_code

if r.status_code != 200:
    print 'error in result !'
    sys.exit(1)

print '200 OK'

event_json = json.loads(r.text)

for i in event_json:
    print i['resource'] + ' -> ' + i['state']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment