Closed MLnick closed 6 years ago
cc @rhagarty
This doesn't fix the issue for me. The API-KEY is not the issue, it's: import tmdbsimple as tmdb
I do not have tmdbsimple installed on my machine. Since loading it is 'optional', we should either 1) handle it not being there 2) make it mandatory that the user install it
Here are the errors I'm getting related to this -
1) error when performing the optional step to load the tmdb api (which is reasonable error): NameError Traceback (most recent call last)
The 2nd error is a bug - will fix that.
The 1st error is really weird - it is like it can't actually catch the module not found exception.
What environment are you using (Python version etc)?
The only other solution would be to just catch Exception
there instead.
I'd make the API access mandatory - but I actually sort of forgot that you have to fill in that form and wait for an API key... it is some friction that I worry would deter quite a few potential users. So first prize will be to correctly handle it with no API access.
I'm using Python 2.7.10 I don't have 3.X installed
Yeah, you need to handle just Exception
exception ModuleNotFoundError A subclass of ImportError which is raised by import when a module could not be located. It is also raised when None is found in sys.modules.
New in version 3.6.
def get_poster_url(id):
"""Fetch movie poster image URL from TMDb API given a tmdbId"""
IMAGE_URL = 'https://image.tmdb.org/t/p/w500'
try:
import tmdbsimple as tmdb
from tmdbsimple import APIKeyError
try:
movie = tmdb.Movies(id).info()
poster_url = IMAGE_URL + movie['poster_path'] if 'poster_path' in movie and movie['poster_path'] is not None else ""
return poster_url
except APIKeyError as ae:
return "KEY_ERR"
except Exception as ex:
return "NA"
This fixed the 5(a) recommendation errors for me. I see the movie titles display correctly.
Still get the 5(b) errors.
@rhagarty latest commit should fix the 5(b) errors.
@rhagarty and also pushed commit to use Exception
instead of ModuleNotFoundError
.
Hopefully this should all work for you now!
Resolves #16