Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Fix #27. Extract country_code from region in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
argrento committed Feb 23, 2021
1 parent d0813e2 commit 750b4ee
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions huami_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ def get_access_token(self) -> str:
raise ValueError("No 'access' parameter in login url.")

if 'country_code' not in redirect_url_parameters:
raise ValueError("No 'country_code' parameter in login url.")
# Sometimes for no reason server does not return country_code
# In this case we extract country_code from region, because it looks
# like this: 'eu-central-1'
region = redirect_url_parameters['region'][0]
self.country_code = region[0:2].upper()

else:
self.country_code = redirect_url_parameters['country_code']

self.access_token = redirect_url_parameters['access']
self.country_code = redirect_url_parameters['country_code']

print("Token: {}".format(self.access_token))
return self.access_token
Expand Down

0 comments on commit 750b4ee

Please sign in to comment.