Skip to content

Instantly share code, notes, and snippets.

@ThrowsException
Created March 18, 2019 02:25
Show Gist options
  • Save ThrowsException/7a50ddcca586da13abb653cc0002ef29 to your computer and use it in GitHub Desktop.
Save ThrowsException/7a50ddcca586da13abb653cc0002ef29 to your computer and use it in GitHub Desktop.
PBX device state
import urllib.request
# create a password manager
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
# Add the username and password.
# If we knew the realm, we could use it instead of None.
top_level_url = "http://192.168.1.218:8088/ari/"
password_mgr.add_password(None, top_level_url, "testuser", "password")
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
# create "opener" (OpenerDirector instance)
opener = urllib.request.build_opener(handler)
# use the opener to fetch a URL
opener.open("http://192.168.1.218")
# Install the opener.
# Now all calls to urllib.request.urlopen use our opener.
urllib.request.install_opener(opener)
with urllib.request.urlopen('http://192.168.1.218:8088/ari/deviceStates') as response:
html = response.read()
print(html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment