diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index 0793bc9..3c1bf00 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -440,12 +440,12 @@ class InstaloaderContext: :raises ConnectionException: When query repeatedly failed. .. versionadded:: 4.2.1""" - tempsession = copy_session(self._session) - tempsession.headers['User-Agent'] = 'Instagram 10.3.2 (iPhone7,2; iPhone OS 9_3_3; en_US; en-US; ' \ - 'scale=2.00; 750x1334) AppleWebKit/420+' - for header in ['Host', 'Origin', 'X-Instagram-AJAX', 'X-Requested-With']: - tempsession.headers.pop(header, None) - return self.get_json(path, params, 'i.instagram.com', tempsession) + with copy_session(self._session) as tempsession: + tempsession.headers['User-Agent'] = 'Instagram 10.3.2 (iPhone7,2; iPhone OS 9_3_3; en_US; en-US; ' \ + 'scale=2.00; 750x1334) AppleWebKit/420+' + for header in ['Host', 'Origin', 'X-Instagram-AJAX', 'X-Requested-With']: + tempsession.headers.pop(header, None) + return self.get_json(path, params, 'i.instagram.com', tempsession) def write_raw(self, resp: Union[bytes, requests.Response], filename: str) -> None: """Write raw response data into a file.""" diff --git a/test/instaloader_unittests.py b/test/instaloader_unittests.py index a2fd6be..209db06 100644 --- a/test/instaloader_unittests.py +++ b/test/instaloader_unittests.py @@ -130,6 +130,9 @@ class TestInstaloaderLoggedIn(TestInstaloaderAnonymously): def test_private_profile_paging(self): self.post_paging_test(instaloader.Profile.from_username(self.L.context, PRIVATE_PROFILE).get_posts()) + def test_profile_pic_download(self): + self.L.download_profile(PUBLIC_PROFILE, profile_pic_only=True) + def test_feed_download(self): self.L.download_feed_posts(NORMAL_MAX_COUNT)