IBM / elasticsearch-spark-recommender

Use Jupyter Notebooks to demonstrate how to build a Recommender with Apache Spark & Elasticsearch
https://developer.ibm.com/code/patterns/build-a-recommender-with-apache-spark-and-elasticsearch/
Apache License 2.0
838 stars 266 forks source link

"Recommendations" error #10

Closed rhagarty closed 6 years ago

rhagarty commented 6 years ago

All the recommendation steps at the end of the notebook had errors, all similar to the following:

NameError Traceback (most recent call last)

in () ----> 1 display_user_recs(12, num=5, num_last=5) in display_user_recs(the_id, q, num, num_last, index) 103 i = 0 104 for movie in user_movies: --> 105 movie_im_url = get_poster_url(movie['tmdbId']) 106 movie_title = movie['title'] 107 user_html += "
%s
" % (movie_title, movie_im_url) in get_poster_url(id) 9 poster_url = IMAGE_URL + movie['poster_path'] if 'poster_path' in movie and movie['poster_path'] is not None else "" 10 return poster_url ---> 11 except ModuleNotFoundError: 12 return "NA" 13 NameError: global name 'ModuleNotFoundError' is not defined NOTE - this is probably related to the fact that I did NOT do the optional step of setting up the tmdb.API_KEY (I had errors). If so, the name of the recommended movie should still be listed, even if it's poster can't be found. Otherwise, the optional step should probably be required.
MLnick commented 6 years ago

Ah - so you did install tmdbsimple but did not set the API_KEY? I'll amend the code to catch that error too so that it falls back to the text-only display.

MLnick commented 6 years ago

I can't reproduce this exact error.

If I have installed tmdbsimple, but did not run the "Toy Story poster test cell", and also have not set the API key, I get:

APIKeyError                               Traceback (most recent call last)
<ipython-input-28-13f0c7366a96> in <module>()
----> 1 display_similar(2628, num=5)

<ipython-input-27-9c5a8e0290b5> in display_similar(the_id, q, num, index, dt)
    133     """
    134     movie, recs = get_similar(the_id, q, num, index, dt)
--> 135     q_im_url = get_poster_url(movie['tmdbId'])
    136     if q_im_url == "NA":
    137         display(HTML("<i>Cannot import tmdbsimple, no movie posters will be displayed!</i>"))

<ipython-input-27-9c5a8e0290b5> in get_poster_url(id)
      6     try:
      7         import tmdbsimple as tmdb
----> 8         movie = tmdb.Movies(id).info()
      9         poster_url = IMAGE_URL + movie['poster_path'] if 'poster_path' in movie and movie['poster_path'] is not None else ""
     10         return poster_url

~/miniconda3/lib/python3.6/site-packages/tmdbsimple/movies.py in info(self, **kwargs)
     61         path = self._get_id_path('info')
     62 
---> 63         response = self._GET(path, kwargs)
     64         self._set_attrs_to_values(response)
     65         return response

~/miniconda3/lib/python3.6/site-packages/tmdbsimple/base.py in _GET(self, path, params)
     83 
     84     def _GET(self, path, params=None):
---> 85         return self._request('GET', path, params=params)
     86 
     87     def _POST(self, path, params=None, payload=None):

~/miniconda3/lib/python3.6/site-packages/tmdbsimple/base.py in _request(self, method, path, params, payload)
     71     def _request(self, method, path, params=None, payload=None):
     72         url = self._get_complete_url(path)
---> 73         params = self._get_params(params)
     74 
     75         response = requests.request(

~/miniconda3/lib/python3.6/site-packages/tmdbsimple/base.py in _get_params(self, params)
     60         from . import API_KEY
     61         if not API_KEY:
---> 62             raise APIKeyError
     63 
     64         api_dict = {'api_key': API_KEY}

APIKeyError: 

However if I do run the poster test cell I then get:

HTTPError: 401 Client Error: Unauthorized for url: https://api.themoviedb.org/3/movie/1893?api_key=YOUR_API_KEY

What Python version are you using?