From b224d0763375ad0c9db3629c1907f807af5397c8 Mon Sep 17 00:00:00 2001 From: qqaatw Date: Mon, 2 May 2022 01:25:31 +0800 Subject: [PATCH] For the same import, using the same device id --- Taipower/__init__.py | 3 +++ Taipower/connection.py | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Taipower/__init__.py b/Taipower/__init__.py index 7a05fd1..60fe829 100644 --- a/Taipower/__init__.py +++ b/Taipower/__init__.py @@ -3,7 +3,10 @@ import asyncio import sys +import uuid +DEVICE_ID = str(uuid.uuid4()) + if sys.platform == "win32": # https://stackoverflow.com/questions/61543406/asyncio-run-runtimeerror-event-loop-is-closed asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) \ No newline at end of file diff --git a/Taipower/connection.py b/Taipower/connection.py index a1deaff..b3e10a6 100644 --- a/Taipower/connection.py +++ b/Taipower/connection.py @@ -1,4 +1,3 @@ -import uuid import json import logging import time @@ -7,7 +6,7 @@ from datetime import datetime import httpx -from . import utility +from . import DEVICE_ID, utility ENDPOINT = "mapp-2019.taipower.com.tw" BASIC_AUTH = "dHBlYy13U1pvLTVDNjZTZG84ZzM6X1UyVlpZd05kWi1hTW9ILV9fZlctZ3ROR0lwVmgydy4=" @@ -150,7 +149,7 @@ def login(self, use_refresh_token=False): "password": utility.des_encrypt(self._password), "grant_type": "password", "scope": "tpec", - "device_id": str(uuid.uuid4()), + "device_id": DEVICE_ID, "appVersion": APP_VERSION, }