From 98791fb0aa64ea7ad40b8683bafbe8475f3413c8 Mon Sep 17 00:00:00 2001 From: Hector Oliveros Date: Sun, 12 May 2024 14:16:36 -0400 Subject: [PATCH] Add login required message when getting comments (#2237) The comment function in the command line options documentation and the main program file has been edited to state that it now requires login. This change was crucial as the additional requests to Instagram server made for each post necessitate user authentication. --- docs/cli-options.rst | 2 +- instaloader/__main__.py | 2 +- instaloader/structures.py | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/cli-options.rst b/docs/cli-options.rst index 05a0206..2f8b7d3 100644 --- a/docs/cli-options.rst +++ b/docs/cli-options.rst @@ -67,7 +67,7 @@ What to Download of each Post Download and update comments for each post. This requires an additional request to the Instagram server for each post, which is why it is disabled by - default. + default. Requires :option:`--login`. .. option:: --no-captions diff --git a/instaloader/__main__.py b/instaloader/__main__.py index c7c46b1..5a8e5ba 100644 --- a/instaloader/__main__.py +++ b/instaloader/__main__.py @@ -367,7 +367,7 @@ def main(): g_post.add_argument('-C', '--comments', action='store_true', help='Download and update comments for each post. ' 'This requires an additional request to the Instagram ' - 'server for each post, which is why it is disabled by default.') + 'server for each post, which is why it is disabled by default. Requires --login.') g_post.add_argument('--no-captions', action='store_true', help='Do not create txt files.') g_post.add_argument('--post-metadata-txt', action='append', diff --git a/instaloader/structures.py b/instaloader/structures.py index b99ca87..c0dc373 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -685,6 +685,9 @@ class Post: .. versionchanged:: 4.7 Change return type to ``Iterable``. """ + if not self._context.is_logged_in: + raise LoginRequiredException("--login required to access comments of a post.") + def _postcommentanswer(node): return PostCommentAnswer(id=int(node['id']), created_at_utc=datetime.utcfromtimestamp(node['created_at']),