From 77ca78e97796e9fa67841b7499e0b77e4d5a2c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Koch-Kramer?= Date: Tue, 7 Aug 2018 19:16:08 +0200 Subject: [PATCH] Fix logging out when download profile_pic fails Add try-finally-block to InstaloaderContext.anonymous_copy(). Fixes #159. --- instaloader/instaloadercontext.py | 10 ++++++---- instaloader/structures.py | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index 7cf4700..d17ce43 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -75,10 +75,12 @@ class InstaloaderContext: username = self.username self._session = self.get_anonymous_session() self.username = None - yield self - self._session.close() - self.username = username - self._session = session + try: + yield self + finally: + self._session.close() + self.username = username + self._session = session @property def is_logged_in(self) -> bool: diff --git a/instaloader/structures.py b/instaloader/structures.py index da85d35..208a67d 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -552,6 +552,8 @@ class Profile: @property def has_viewable_story(self) -> bool: """ + .. deprecated:: 4.0.6 + Some stories are private. This property determines if the :class:`Profile` has at least one story which can be viewed using the associated :class:`InstaloaderContext`, i.e. the viewer has privileges to view it.