mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-15 23:00:18 -07:00
Recreate sessions on the fly
Adapts #88 to avoid a global session object.
This commit is contained in:
parent
6af5eb1ce1
commit
fd5a695988
@ -65,7 +65,7 @@ def get_wideq_logger() -> logging.Logger:
|
||||
LOGGER = get_wideq_logger()
|
||||
|
||||
|
||||
def get_retry_session():
|
||||
def retry_session():
|
||||
"""Get a Requests session that retries HTTP and HTTPS requests.
|
||||
"""
|
||||
# Adapted from:
|
||||
@ -84,9 +84,6 @@ def get_retry_session():
|
||||
return session
|
||||
|
||||
|
||||
SESSION = get_retry_session()
|
||||
|
||||
|
||||
def set_log_level(level: int):
|
||||
logger = get_wideq_logger()
|
||||
logger.setLevel(level)
|
||||
@ -201,7 +198,8 @@ def lgedm_post(url, data=None, access_token=None, session_id=None):
|
||||
if session_id:
|
||||
headers['x-thinq-jsessionId'] = session_id
|
||||
|
||||
res = SESSION.post(url, json={DATA_ROOT: data}, headers=headers)
|
||||
with retry_session() as session:
|
||||
res = session.post(url, json={DATA_ROOT: data}, headers=headers)
|
||||
out = res.json()[DATA_ROOT]
|
||||
|
||||
# Check for API errors.
|
||||
@ -293,7 +291,8 @@ def refresh_auth(oauth_root, refresh_token):
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
|
||||
res = SESSION.post(token_url, data=data, headers=headers)
|
||||
with retry_session() as session:
|
||||
res = session.post(token_url, data=data, headers=headers)
|
||||
res_data = res.json()
|
||||
|
||||
if res_data['status'] != 1:
|
||||
|
Loading…
x
Reference in New Issue
Block a user