Python-Unifi-Client 1.1.1__tar.gz → 1.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/PKG-INFO +1 -1
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/python_unifi_client/client.py +13 -16
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/python_unifi_client.egg-info/PKG-INFO +1 -1
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/setup.py +1 -1
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/README.md +0 -0
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/python_unifi_client/__init__.py +0 -0
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/python_unifi_client.egg-info/SOURCES.txt +0 -0
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/python_unifi_client.egg-info/dependency_links.txt +0 -0
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/python_unifi_client.egg-info/top_level.txt +0 -0
- {python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/setup.cfg +0 -0
|
@@ -10,10 +10,6 @@ import http.client as http_client
|
|
|
10
10
|
import logging
|
|
11
11
|
import base64
|
|
12
12
|
|
|
13
|
-
logging.basicConfig(level=logging.DEBUG)
|
|
14
|
-
logging.getLogger('requests.packages.urllib3').setLevel(logging.DEBUG)
|
|
15
|
-
http_client.HTTPConnection.debuglevel = 1
|
|
16
|
-
|
|
17
13
|
# Custom exceptions mirroring PHP equivalents
|
|
18
14
|
class CurlExtensionNotLoadedException(Exception):
|
|
19
15
|
def __init__(self):
|
|
@@ -109,6 +105,7 @@ class Client:
|
|
|
109
105
|
self._last_results_raw = None
|
|
110
106
|
self._cookies_created_at = 0
|
|
111
107
|
self._exec_retries = 0
|
|
108
|
+
self.debug = False
|
|
112
109
|
|
|
113
110
|
self._curl_headers = {
|
|
114
111
|
'Accept': 'application/json',
|
|
@@ -198,7 +195,7 @@ class Client:
|
|
|
198
195
|
except RequestException as e:
|
|
199
196
|
raise CurlGeneralErrorException(str(e), None, None)
|
|
200
197
|
|
|
201
|
-
if self.
|
|
198
|
+
if self.debug:
|
|
202
199
|
print("\n-----------LOGIN-------------")
|
|
203
200
|
print("GET Options:", get_options)
|
|
204
201
|
print("POST Options:", post_options)
|
|
@@ -259,7 +256,7 @@ class Client:
|
|
|
259
256
|
return self.fetch_results(f"/api/s/{self._site}/stat/sysinfo")
|
|
260
257
|
|
|
261
258
|
def get_clients(self):
|
|
262
|
-
return self.
|
|
259
|
+
return self.fetch_results(f"/api/s/{self._site}/stat/sta")
|
|
263
260
|
|
|
264
261
|
def block_client(self, mac):
|
|
265
262
|
return self._request(f"/api/s/{self._site}/cmd/stamgr", method='POST', payload={'cmd': 'block-sta', 'mac': mac})
|
|
@@ -751,7 +748,7 @@ class Client:
|
|
|
751
748
|
return self.fetch_results(f"/api/s/{self._site}/stat/device", login_required=True, prefix_path=True)
|
|
752
749
|
|
|
753
750
|
def get_device(self, device_id):
|
|
754
|
-
return self.
|
|
751
|
+
return self.fetch_results(f"/api/s/{self._site}/stat/device/{device_id}")
|
|
755
752
|
|
|
756
753
|
def get_wlan(self, wlan_id: str):
|
|
757
754
|
"""
|
|
@@ -928,7 +925,7 @@ class Client:
|
|
|
928
925
|
'include_traffic_usage': include_traffic_usage,
|
|
929
926
|
'include_unifi_devices': include_unifi_devices,
|
|
930
927
|
})
|
|
931
|
-
return self.fetch_results(f"/v2/api/site/{self._site}/clients/active?{query}")
|
|
928
|
+
return self.fetch_results(f"/v2/api/site/{self._site}/clients/active?{query}", prefix_path=True)
|
|
932
929
|
|
|
933
930
|
def list_clients_history(self, only_non_blocked: bool = True, include_unifi_devices: bool = True, within_hours: int = 0):
|
|
934
931
|
"""Fetch offline client device history."""
|
|
@@ -1834,7 +1831,7 @@ class Client:
|
|
|
1834
1831
|
"""Generate a controller backup for the past N days."""
|
|
1835
1832
|
payload = {'cmd': 'backup', 'days': days}
|
|
1836
1833
|
result = self.fetch_results(f"/proxy/network/api/s/{self._site}/cmd/backup", payload=payload, prefix_path=False, boolean=False)
|
|
1837
|
-
print(f"RAW RESULT FROM FETCH_RESULTS(): {result}")
|
|
1834
|
+
print(f"RAW RESULT FROM FETCH_RESULTS(): {result}") if self.debug else None
|
|
1838
1835
|
return result
|
|
1839
1836
|
|
|
1840
1837
|
def download_backup(self, filepath: str):
|
|
@@ -2330,7 +2327,7 @@ class Client:
|
|
|
2330
2327
|
if isinstance(self._last_results_raw, str):
|
|
2331
2328
|
try:
|
|
2332
2329
|
response = json.loads(self._last_results_raw)
|
|
2333
|
-
print("Fetched response:", response)
|
|
2330
|
+
print("Fetched response:", response) if self.debug else None
|
|
2334
2331
|
except:
|
|
2335
2332
|
self._get_json_last_error()
|
|
2336
2333
|
raise
|
|
@@ -2340,8 +2337,8 @@ class Client:
|
|
|
2340
2337
|
self._last_error_message = ''
|
|
2341
2338
|
if 'data' in response:
|
|
2342
2339
|
if isinstance(response['data'], list):
|
|
2343
|
-
print("Response inside fetch_results():", response)
|
|
2344
|
-
print("Data:", response.get("data"))
|
|
2340
|
+
print("Response inside fetch_results():", response) if self.debug else None
|
|
2341
|
+
print("Data:", response.get("data")) if self.debug else None
|
|
2345
2342
|
return response['data'] if not boolean else True
|
|
2346
2343
|
return [response['data']] if not boolean else True
|
|
2347
2344
|
return True
|
|
@@ -2471,7 +2468,7 @@ class Client:
|
|
|
2471
2468
|
|
|
2472
2469
|
# 9) handle expired auth
|
|
2473
2470
|
if http_code == 401:
|
|
2474
|
-
if self.
|
|
2471
|
+
if self.debug:
|
|
2475
2472
|
print(f"exec_curl: 401 on {url}, need to re-login")
|
|
2476
2473
|
if self._exec_retries == 0:
|
|
2477
2474
|
# clear stored cookie/token
|
|
@@ -2485,14 +2482,14 @@ class Client:
|
|
|
2485
2482
|
# attempt re-login
|
|
2486
2483
|
from time import sleep
|
|
2487
2484
|
if self.login():
|
|
2488
|
-
if self.
|
|
2485
|
+
if self.debug:
|
|
2489
2486
|
print("exec_curl: re-login succeeded, retrying exec_curl")
|
|
2490
2487
|
return self.exec_curl(path, payload, prefix_path)
|
|
2491
2488
|
raise LoginFailedException('Cookie/Token expired and re-login failed.')
|
|
2492
2489
|
raise LoginFailedException('Login failed, check credentials.')
|
|
2493
2490
|
|
|
2494
2491
|
# 10) debug dump
|
|
2495
|
-
if self.
|
|
2492
|
+
if self.debug:
|
|
2496
2493
|
print("\n---------cURL INFO-----------")
|
|
2497
2494
|
print("Options:", opts)
|
|
2498
2495
|
print("URL & PAYLOAD:", url)
|
|
@@ -2523,7 +2520,7 @@ class Client:
|
|
|
2523
2520
|
}
|
|
2524
2521
|
|
|
2525
2522
|
# Verbose logging if debug
|
|
2526
|
-
if self.
|
|
2523
|
+
if self.debug:
|
|
2527
2524
|
# shows per-request wire logs
|
|
2528
2525
|
logging.getLogger('urllib3').setLevel(logging.DEBUG)
|
|
2529
2526
|
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
|
5
5
|
|
|
6
6
|
setuptools.setup(
|
|
7
7
|
name="python_unifi_client",
|
|
8
|
-
version="1.1.
|
|
8
|
+
version="1.1.3",
|
|
9
9
|
author="Michael Lapinski",
|
|
10
10
|
author_email="michaellapinski787@gmail.com",
|
|
11
11
|
descripton="A python version of a github Art-of-Wifi/Unifi-API-Client",
|
|
File without changes
|
|
File without changes
|
{python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/python_unifi_client.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{python_unifi_client-1.1.1 → python_unifi_client-1.1.3}/python_unifi_client.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|