Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to define a name for an exception in python?

I`m trying to handle the exception ‘ProfileNotExistsException’ and the code is as follows:

    try:
        profile = instaloader.Profile.from_username(bot.context, followees[i])
        #Other statements
    except ProfileNotExistsException:
        print('exception')

But This NameError is occurring.

NameError                                 Traceback (most recent call last)
Input In [11], in <cell line: 2>()
      6     allfolloweesDataList.append((profile.userid,profile.username,profile.full_name,profile.followers,profile.followees,profile.is_verified,profile.biography,profile.external_url))
      7     print(i,end=',')
----> 8 except ProfileNotExistsException:
      9     print('exception')

NameError: name 'ProfileNotExistsException' is not defined

How can I define a name for an exception like this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Looking at the source code for the instaloader package, I believe this is what you are looking for:

from instaloader.exceptions import ProfileNotExistsException

try:
    profile = instaloader.Profile.from_username(bot.context, followees[i])
    ...
except ProfileNotExistsException:
    print('exception')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading