Skip to content

Commit

Permalink
Handle re-login method ValueError exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
RenierM26 committed Mar 9, 2021
1 parent f6b36ed commit e0a7027
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
30 changes: 12 additions & 18 deletions pyezviz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _login(self):
json_result = req.json()

except ValueError as err:
raise PyEzvizError("Can't decode response") from err
raise PyEzvizError("Can't login response") from err

if self._session.cookies.get("REDIRECTCOOKIE", domain=API_BASE_TLD):
print("Your region is incorrect!")
Expand All @@ -97,7 +97,7 @@ def _login(self):
raise PyEzvizError("Incorrect login details")

if json_result["retcode"] == "1002":
raise PyEzvizError("Login error: Captcha required")
raise PyEzvizError("Login error: Check your password!")

if json_result["retcode"] == "1005":
raise PyEzvizError("Login error: Incorrect Captcha code")
Expand Down Expand Up @@ -149,19 +149,16 @@ def _login_api(self):

req.raise_for_status()

json_result = req.json()

if json_result["meta"]["code"] == 1100:
region = json_result["loginArea"]["apiDomain"]
raise PyEzvizError(f"region url: {region} ")

except requests.HTTPError as err:
raise PyEzvizError("Can not login to API") from err

if req.status_code != 200:
raise PyEzvizError(
f"Login error: Please check your username/password: {req.text} "
)
"Login error: Please check your username/password"
) from err

json_result = req.json()

if json_result["meta"]["code"] == 1100:
region = json_result["loginArea"]["apiDomain"]
raise PyEzvizError(f"region url: {region} ")

return True

Expand Down Expand Up @@ -556,18 +553,15 @@ def login(self):
req.raise_for_status()

except requests.HTTPError as err:
if err.response.status_code == 401 or 504:
self._login()

raise PyEzvizError(
"Could not access Ezviz login check API: " + str(err)
) from err

try:
response_json = req.json()

except ValueError as err:
raise PyEzvizError("Can't decode response" + str(err)) from err
except ValueError:
self._login()

if response_json["success"] != "success":
self._login()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='pyezviz',
version="0.1.7.7",
version="0.1.7.8",
license='Apache Software License 2.0',
author='Pierre Ourdouille',
author_email='baqs@users.github.com',
Expand Down

0 comments on commit e0a7027

Please sign in to comment.