Python IMDbPY – Error Handling
Last Updated :
16 Jun, 2021
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
from imdb import IMDb, IMDbError
try :
ia = IMDb()
people = ia.get_person( 'abcd' )
except IMDbError as e:
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
from imdb import IMDb, IMDbError
try :
ia = IMDb()
people = ia.search_person( 'abcd' )
except IMDbError as e:
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'))}
Share your thoughts in the comments
Please Login to comment...