moogar0880 / PyTrakt

A Pythonic interface to the Trakt.tv REST API
Other
66 stars 51 forks source link

AttributeError: 'Movie' object has no attribute 'trakt' #158

Open Ashish0804 opened 3 years ago

Ashish0804 commented 3 years ago

Looks like trakt was never initialized and thus error. https://github.com/moogar0880/PyTrakt/blob/033f2ed37590621868bba6253ed5435e61e69171/trakt/movies.py#L194

Changing it to trakt_id should fix things but I haven't tested it myself.

Here's the full error log

Traceback (most recent call last):
  File ".\add2traktlist.py", line 56, in <module>
    main()
  File ".\add2traktlist.py", line 51, in main
    traktList.add_items(trakt_object)
  File "C:\Users\Ashish\Anaconda3\lib\site-packages\trakt\core.py", line 586, in inner
    url, generator, args = self._get_first(f, *args, **kwargs)
  File "C:\Users\Ashish\Anaconda3\lib\site-packages\trakt\core.py", line 494, in _get_first
    uri = next(generator)
  File "C:\Users\Ashish\Anaconda3\lib\site-packages\trakt\users.py", line 160, in add_items
    movies = [m.ids for m in items if isinstance(m, Movie)]
  File "C:\Users\Ashish\Anaconda3\lib\site-packages\trakt\users.py", line 160, in <listcomp>
    movies = [m.ids for m in items if isinstance(m, Movie)]
  File "C:\Users\Ashish\Anaconda3\lib\site-packages\trakt\movies.py", line 194, in ids
    return {'ids': {'trakt': self.trakt, 'slug': self.slug,
AttributeError: 'Movie' object has no attribute 'trakt'

Here's how Movie object is being used in my code

Movie(title=res['Title'], imdb_id=res['imdbID'])

res is the response for OMDB api.

Ashish0804 commented 3 years ago

There are other errors on that line

This fixed them

        return {'ids': {'trakt': self.trakt_id, 'slug': self.slug,
                        'imdb': self.imdb_id, 'tmdb': self.tmdb_id}}
glensc commented 2 years ago

you are using constructor with data in an unexpected way:

Movie(title=res['Title'], imdb_id=res['imdbID'])

you need to pass ids as ids=dict rather than individual parameters:

Movie(title=res['Title'], ids= {'trakt': trakt_id, 'slug': self.slug,  'imdb': self.imdb_id, 'tmdb': self.tmdb_id})

this is later filled into *_id via extract_ids (in method _build).

glensc commented 1 year ago

Adding .trakt in my fork:

but due to different reasons.