Skip to content

Commit

Permalink
Merge pull request #1 from voice1/master
Browse files Browse the repository at this point in the history
Added authentication method check
  • Loading branch information
matt-jordan committed Feb 15, 2018
2 parents 40853a1 + d1353a9 commit 9a8d208
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion pyswitchvox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,23 @@ def __init__(self, address, username, password, timeout=30):

self._address = address
self._session = requests.Session()
self._session.auth = HTTPDigestAuth(username, password)
self._session.auth = self._detect_auth(username, password, address)
self.timeout = timeout

def _detect_auth(self, username, password, hostname):
"""Switchvox 6.6.0.x changed authentication methods.
Returns the request auth object.
"""
auth = HTTPDigestAuth(username, password)

r = self._session.post("https://" + hostname + "/json",
json={},
auth=auth,
verify=False)
if r.status_code == 401:
auth = requests.auth.HTTPBasicAuth(username, password)
return auth

def close(self):
"""Close the client connection
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="pyswitchvox",
version="0.0.1",
version="0.0.2",
license="BSD 3-Clause License",
description="Library for accessing the Switchvox Extend API",
long_description=open(os.path.join(os.path.dirname(__file__),
Expand Down

0 comments on commit 9a8d208

Please sign in to comment.