Skip to content

Commit 9a8d208

Browse files
authored
Merge pull request #1 from voice1/master
Added authentication method check
2 parents 40853a1 + d1353a9 commit 9a8d208

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pyswitchvox/client.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,23 @@ def __init__(self, address, username, password, timeout=30):
6565

6666
self._address = address
6767
self._session = requests.Session()
68-
self._session.auth = HTTPDigestAuth(username, password)
68+
self._session.auth = self._detect_auth(username, password, address)
6969
self.timeout = timeout
7070

71+
def _detect_auth(self, username, password, hostname):
72+
"""Switchvox 6.6.0.x changed authentication methods.
73+
Returns the request auth object.
74+
"""
75+
auth = HTTPDigestAuth(username, password)
76+
77+
r = self._session.post("https://" + hostname + "/json",
78+
json={},
79+
auth=auth,
80+
verify=False)
81+
if r.status_code == 401:
82+
auth = requests.auth.HTTPBasicAuth(username, password)
83+
return auth
84+
7185
def close(self):
7286
"""Close the client connection
7387
"""

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name="pyswitchvox",
15-
version="0.0.1",
15+
version="0.0.2",
1616
license="BSD 3-Clause License",
1717
description="Library for accessing the Switchvox Extend API",
1818
long_description=open(os.path.join(os.path.dirname(__file__),

0 commit comments

Comments
 (0)