From 0648876cc070e976b95b43a74e0bbdab1be35b14 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 20 Jan 2018 16:54:53 -0500 Subject: [PATCH] Extract new access token --- wideq.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wideq.py b/wideq.py index a927044..b17a3bd 100644 --- a/wideq.py +++ b/wideq.py @@ -55,6 +55,13 @@ class NotLoggedInError(APIError): pass +class TokenError(APIError): + """An authentication token was rejected.""" + + def __init__(self): + pass + + def lgedm_post(url, data=None, access_token=None, session_id=None): """Make an HTTP request in the format used by the API servers. @@ -232,10 +239,13 @@ class Auth(object): 'lgemp-x-date': timestamp, 'Accept': 'application/json', } - print(headers) res = requests.post(token_url, data=data, headers=headers) - print(res.text) + res_data = res.json() + + if res_data['status'] != 1: + raise TokenError() + return res_data['access_token'] class Session(object):