Bootstrap FreeKB - Python (Scripting) - Resolve "IndexError: list index out of range"
Python (Scripting) - Resolve "IndexError: list index out of range"

Updated:   |  Python (Scripting) articles

Let's say something like this is being returned.

Traceback (most recent call last):
  File "/usr/local/scripts/backup_databases.py", line 250, in <module>
    if object['Key'].split('.')[1]:
IndexError: list index out of range

 

Notice in this example that I got this on line 250 of my /usr/local/scripts/backup_databases.py script with command if object['Key'].split('.')[1]. This can be handled using try except error handling.

try:
  object['Key'].split('.')[1]
except IndexError:
  pass
else:
  obj = object['Key'].split('.')[1]

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter d097f4 in the box below so that we can be sure you are a human.