0

I'm trying to work with a module i've imported "thetvdb" from https://github.com/dbr/tvdb_api. I managed to import the module into my code but i'm trying to get the errors from the module to know the result. show not found, episode not found, etc and I'm unable to successfully do that without breaking the script.

This is my current code:

#!/usr/bin/env python3
from tvdb_api import tvdb_api
t = tvdb_api.Tvdb()

show_name = raw_input("What is the tv show? ")
season_num = int(raw_input("What is the season number? "))
episode_num = int(raw_input("What is the episode number? "))
try:
        episode = t[show_name][season_num][episode_num] # get season 1, episode 3 of show
        print episode['episodename'] # Print episode name
except tvdb_api.tvdb_exception:
        print("error")

I want something more than what i'm printing. I've tried a return but python told me it's not in a function. What I think is throwing me off is the fact the error classes are empty.

Here is a snippet of the exception classes in the tvdbapi.py file:

## Exceptions

class tvdb_exception(Exception):
    """Any exception generated by tvdb_api
    """
    pass

class tvdb_error(tvdb_exception):
    """An error with thetvdb.com (Cannot connect, for example)
    """
    pass

class tvdb_userabort(tvdb_exception):
    """User aborted the interactive selection (via
    the q command, ^c etc)
    """
    pass

class tvdb_notauthorized(tvdb_exception):
    """An authorization error with thetvdb.com
    """
    pass

class tvdb_shownotfound(tvdb_exception):
    """Show cannot be found on thetvdb.com (non-existant show)
    """
    pass

class tvdb_seasonnotfound(tvdb_exception):
    """Season cannot be found on thetvdb.com
    """
    pass

class tvdb_episodenotfound(tvdb_exception):
    """Episode cannot be found on thetvdb.com
    """
    pass

class tvdb_resourcenotfound(tvdb_exception):
    """Resource cannot be found on thetvdb.com
    """
    pass
yusof
  • 143
  • 2
  • 14
  • Possible duplicate of [How to print an exception in Python?](https://stackoverflow.com/questions/1483429/how-to-print-an-exception-in-python) – Georgy Apr 08 '19 at 12:59

1 Answers1

1

You may want to print the exception as well:

try:
    # ...
except tvdb_api.tvdb_exception as exc:
    print("error:", exc)
Tiger-222
  • 6,677
  • 3
  • 47
  • 60
  • holy crap. I was trying to print tvdb_api.tvdb_exception at one point. I didn't know you can do as exc and then just print that...it worked! I wish that script had error codes instead of text, but thank you! been reading and banging my head on this for a few hours! – yusof Apr 08 '19 at 06:09