Friday, August 29, 2025
HomeLanguagesPython IMDbPY – Error Handling

Python IMDbPY – Error Handling

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. 
 

Python3




# 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:
     
    # printing the exception
    print(e)


Output : 
 

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

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

Python3




# 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:
     
    # printing the exception
    print(e)


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'))}

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7012 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS