-1

I'm trying to pull data about cinematographers from IMDbPY and i'm encountering a null object. I'm not sure how to deal with that None object in the code. Could someone help me out please?

here's where I have reached.

from imdb import IMDb, IMDbError
ia = IMDb() 
itemdop = ''
doplist = []


items = ["0050083", "6273736", "2582802"]

def imdblistdop(myList=[], *args):
    for x in myList:
      movie = ia.get_movie(x)
      cinematographer = movie.get('cinematographers')[0]
      cinematographer2 = movie.get('cinematographers')
      print(cinematographer)
      print(doplist)
      try:
            itemdop = cinematographer['name']
            doplist.append(itemdop)
      except KeyError as ke:
            print('Nope!')


imdblistdop(items)



The code is not working at all and all i get is this:

Boris Kaufman []


TypeError Traceback (most recent call last) in () 21 22 ---> 23 imdblistdop(items) 24 25

in imdblistdop(myList, *args) 10 for x in myList: 11 movie = ia.get_movie(x) ---> 12 cinematographer = movie.get('cinematographers')[0] 13 cinematographer2 = movie.get('cinematographers') 14 print(cinematographer)

TypeError: 'NoneType' object is not subscriptable

teneb
  • 11
  • 1

1 Answers1

0

cinematographer is a list. It means that you can point to an an entry in the list using its index. Example: cinematographer[2]. You can not use a string to point to an entry in the list.

balderman
  • 22,927
  • 7
  • 34
  • 52
  • Bro there was an error in my code. while editing it for here, i messed up. – teneb Aug 21 '21 at 18:21
  • it parses the first filmid then goes belly up – teneb Aug 21 '21 at 18:23
  • There's an error in the way that i'm trying to handle the error? – teneb Aug 21 '21 at 18:28
  • before `cinematographer = movie.get('cinematographers')[0]` add the line `print(movie.get('cinematographers'))` - what do you get? – balderman Aug 21 '21 at 18:31
  • [] Boris Kaufman [] [] None in imdblistdop(myList, *args) 11 movie = ia.get_movie(x) 12 print(movie.get('cinematographers')) ---> 13 cinematographer = movie.get('cinematographers')[0] 14 cinematographer2 = movie.get('cinematographers') 15 print(cinematographer) TypeError: 'NoneType' object is not subscriptable – teneb Aug 21 '21 at 18:34
  • What is the output of the `print`? put rest of the code in comment – balderman Aug 21 '21 at 18:34
  • dont point to external resources. Just follow what I have asked you to do. – balderman Aug 21 '21 at 18:36
  • or this one? https://colab.research.google.com/drive/1-YOKCOG0vCd6ZXAgDf2EXm2TBzAMRxWp?usp=sharing – teneb Aug 21 '21 at 18:38
  • TypeError: 'NoneType' object is not subscriptable – teneb Aug 21 '21 at 18:40