From 969bf4abfb3c22377f34cbbed4e83decad888b41 Mon Sep 17 00:00:00 2001 From: Paulo Romeira Date: Sun, 6 May 2018 04:44:18 -0300 Subject: [PATCH] Little Logged session fix --- onegram/session.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/onegram/session.py b/onegram/session.py index 0dd90fb..6514ca3 100644 --- a/onegram/session.py +++ b/onegram/session.py @@ -155,7 +155,19 @@ def __init__(self, username=None, password=None, custom_settings={}): super(Login, self).__init__(custom_settings) self.username = self.settings.get('USERNAME') - self.on_open.subscribe(self._login) + # TODO [romeira]: fix sessionlib {06/05/18 04:41} + # self.on_open.subscribe(self._login) + + + def enter_contexts(self): + yield from super(Login, self).enter_contexts() + try: + self._login() + except AuthException as e: + self.logger.error(e) + self.close() + raise e + def _login(self): kw = {} @@ -172,12 +184,7 @@ def _login(self): response = self._requests.post(URLS['login'], **kw) response.raise_for_status() - try: - check_auth(json.loads(response.text)) - except AuthException as e: - self.logger.error(e) - self.close() - raise e + check_auth(json.loads(response.text)) self.user_id = self.cookies.get('ds_user_id')