Skip to content
Related Articles

Related Articles

Python IMDbPY – Error Handling
  • Last Updated : 22 Apr, 2020

In this article we will see how we can handle errors related to IMDb module of Python, error like invalid search or data base error network issues that are related to IMDbPY can be caught by checking for the imdb.IMDbErrorexception

In order to handle error we have to import the following

from imdb import IMDbError

Syntax :

try :

    # code

except IMDbError as e:

    # action to handle it

If any error related to IMDb occur then it will get caught by except block.

Below is the implementation.



filter_none

edit
close

play_arrow

link
brightness_4
code

# importing libraries
from imdb import IMDb, IMDbError
  
# try block
try:
      
    # creating instance of imdb
    ia = IMDb()
      
    # getting person (it accept people id only)
    people = ia.get_person('abcd')
      
# except block   
except IMDbError as e:
      
    # priting the exception
    print(e)

chevron_right


Output :

invalid personID "abcd": invalid literal for int() with base 10: 'abcd'

Another example: In this we have turn off the internet connection

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing libraries
from imdb import IMDb, IMDbError
  
# try block
try:
      
    # creating instance of imdb
    ia = IMDb()
      
    # searching person
    people = ia.search_person('abcd')
      
# except block   
except IMDbError as e:
      
    # priting the exception
    print(e)

chevron_right


Output :

{'errcode': None, 'errmsg': 'None', 'url': 'https://www.imdb.com/find?q=abcd&s=nm', 'proxy': '', 'exception type': 'IOError', 'original exception': URLError(gaierror(11001, 'getaddrinfo failed'))}

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :