diff --git a/instaloader/instaloader.py b/instaloader/instaloader.py index da6eaf5..1b9743f 100644 --- a/instaloader/instaloader.py +++ b/instaloader/instaloader.py @@ -926,8 +926,11 @@ class Instaloader: :return: Instance of current profile """ profile = None - with suppress(ProfileNotExistsException): + profile_name_not_exists_err = None + try: profile = Profile.from_username(self.context, profile_name) + except ProfileNotExistsException as err: + profile_name_not_exists_err = err id_filename = self._get_id_filename(profile_name) try: with open(id_filename, 'rb') as id_file: @@ -960,6 +963,8 @@ class Instaloader: if profile is not None: self.save_profile_id(profile) return profile + if profile_name_not_exists_err: + raise profile_name_not_exists_err raise ProfileNotExistsException("Profile {0} does not exist.".format(profile_name)) def download_profiles(self, profiles: Set[Profile], diff --git a/instaloader/structures.py b/instaloader/structures.py index 041780d..eaf933b 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -534,6 +534,13 @@ class Profile: self._has_full_metadata = True self._rhx_gis = metadata.get('rhx_gis') except (QueryReturnedNotFoundException, KeyError) as err: + top_search_results = TopSearchResults(self._context, self.username) + similar_profiles = [profile.username for profile in top_search_results.get_profiles()] + if similar_profiles: + raise ProfileNotExistsException('Profile {} does not exist.\nThe most similar profile{}: {}.' + .format(self.username, + 's are' if len(similar_profiles) > 1 else ' is', + ', '.join(similar_profiles[0:5]))) from err raise ProfileNotExistsException('Profile {} does not exist.'.format(self.username)) from err def _metadata(self, *keys) -> Any: