wagnerrp / pytmdb3

Python interface to TheMovieDB.org v3 API
BSD 3-Clause "New" or "Revised" License
122 stars 36 forks source link

NoneType is not iterable #29

Open ghost opened 11 years ago

ghost commented 11 years ago

Hi,

I am using PyTMDB3 and for the most part successfully, although I have 1 problem. I have the following code:

import os

from tmdb3 import searchMovie
from tmdb3 import set_key

set_key('<APIKEY>')

for path, subdirs, files in os.walk(r'/media/Movies'):
    files = [ file for file in files if not file.endswith( ('.nfo','.tbn','.jpg','.xml','.srt') ) ]
    for filename in files:
        fname = str(os.path.splitext(filename)[0])
        res = searchMovie(fname)
    print (res[0])

It goes through my movies and prints out the movie name found on tmdb. It works although there are 5 movies in which it doesnt work and I get an error and I cant figure out why.

The movies are Madagascar, Robin Hood, The Grey, The Watch and Zombieland. I can see that they are all on tmdb so am not sure why it isnt finding them.

The error is: Traceback (most recent call last): File "scan.py", line 14, in res = searchMovie(fname) File "/usr/local/lib/python2.7/dist-packages/tmdb3/tmdb_api.py", line 121, in searchMovie return MovieSearchResult(Request('search/movie', kwargs), locale=locale) File "/usr/local/lib/python2.7/dist-packages/tmdb3/tmdb_api.py", line 148, in init lambda x: Movie(raw=x, locale=locale)) File "/usr/local/lib/python2.7/dist-packages/tmdb3/pager.py", line 101, in init super(PagedRequest, self).init**(self._getpage(1), 20) File "/usr/local/lib/python2.7/dist-packages/tmdb3/pager.py", line 56, in initself._data = list(iterable) File "/usr/local/lib/python2.7/dist-packages/tmdb3/pager.py", line 108, in _ge tpageyield self._handler(item) File "/usr/local/lib/python2.7/dist-packages/tmdb3/tmdb_api.py", line 148, in lambda x: Movie(raw=x, locale=locale)) File "/usr/local/lib/python2.7/dist-packages/tmdb3/util.py", line 350, in callobj._populate.apply(kwargs['raw'], False) File "/usr/local/lib/python2.7/dist-packages/tmdb3/util.py", line 83, in apply if (k in TypeError: argument of type 'NoneType' is not iterable

Thanks for any help.

Jay

wagnerrp commented 11 years ago

For some reason, the API is returning "null"s in the list of results. I'll have to pass this upstream to see what's going on.

wagnerrp commented 11 years ago

It seems these are movies that have been deleted, but haven't been completely flushed out of the API servers. They should be getting server side, but currently aren't.

http://www.themoviedb.org/talk/522e418d760ee3380c10d5a2

ghost commented 11 years ago

I have updated the changes, same issue

wagnerrp commented 11 years ago

It resolves the issue locally, but as the commit message mentioned, it's not a proper fix. It just passes the null entries on to you to deal with.

ghost commented 11 years ago

Sorry I didn't notice that, I have added some checking code and its all working fine again. Thanks for the help.