argrento/huami-token

With Xiami Mi account, only after adding real BT address the script returns the key

b100dian opened this issue · 6 comments

Hi, and thanks for this method of retrieving the auth key.
In my case, using a xiaomi account, I could only find the key after setting self.device_id to the real BT id.
Maybe you could add a parameter for that.
Thanks!

Hi!

You have too many bt-devices in the table? You mean it is hard to find desired device?

No, I only have one device. What I am trying to say is that the script did not work out of the box for me, but only when modifying it to set my real BT address as device_id

That's weird. Can you post the whole output of the script?

Oh, interesting, now it works 😲 !
I do have some unrelated errors after my auth key

Downloading AGPS_ALM...
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 309, in connect
    conn = self._new_conn()
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fe414460df0>: Failed to establish a new connection: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 726, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='s3.us-west-2.amazonaws.com', port=443): Max retries exceeded with url: /huami-public-us2/AGPS_FILES/2020-10-18/1603032007862cep_alm_pak.zip (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe414460df0>: Failed to establish a new connection: [Errno -5] No address associated with hostname'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "huami_token.py", line 229, in <module>
    device.get_gps_data()
  File "huami_token.py", line 175, in get_gps_data
    with requests.get(agps_result['fileUrl'], stream=True) as r:
  File "/usr/lib/python3.8/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='s3.us-west-2.amazonaws.com', port=443): Max retries exceeded with url: /huami-public-us2/AGPS_FILES/2020-10-18/1603032007862cep_alm_pak.zip (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe414460df0>: Failed to establish a new connection: [Errno -5] No address associated with hostname'))

I think you can close this ticket, if somebody observes this situation I was in maybe he or she can make the same modifications as me:

--- a/huami_token.py
+++ b/huami_token.py
@@ -32,10 +32,10 @@ class HuamiAmazfit:
         self.r = str(uuid.uuid4())
 
         # IMEI or something unique
-        self.device_id = "02:00:00:%02x:%02x:%02x" % (random.randint(0, 255),
-                                                      random.randint(0, 255),
-                                                      random.randint(0, 255))
-
+        # self.device_id = "02:00:00:%02x:%02x:%02x" % (random.randint(0, 255),
+        #                                               random.randint(0, 255),
+        #                                               random.randint(0, 255))
+        self.device_id = "TH:ER:EA:AL:BT:ID"
     def get_access_token(self):
         print(f"Getting access token with {self.method} login method...")

To summarize: if device_id is random, no keys are returned, but if you set device_id to your phone mac address, key is returned?

yes, but not phone mac, but watch Bluetooth address
And I was not able to reproduce. so it may have been some other glitch..