Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tmdbsimple error
#1
I'm running into an obstacle in converting my TMDB query script into a function. The only change is having the search query as the only argument in the function and passing that along to the TMDB API. I'm receiving the following error and I have no idea why. Any help would be much appreciated!

Error:
Traceback (most recent call last): File "C:\Users\REMOVED\Python Apps\My Progs\test.py", line 52, in <module> tmdb_search('life') File "C:\Users\REMOVED\Python Apps\My Progs\test.py", line 10, in tmdb_search response = search.movie(query) TypeError: movie() takes 1 positional argument but 2 were given
import tmdbsimple as tmdb
tmdb.API_KEY = 'API KEY REMOVED'
import requests
import locale



def tmdb_search(query):
    search = tmdb.Search()
    response = search.movie(query)
    #print(response)
    list1 = []
    inc = 1
    #generate list for user to review
    for s in search.results:
        print(str(inc) + "." + s['title'] + " " + s['release_date'])
        list1.append(s['id'])
        inc += 1
        if inc > 5:
            break

    #number the list, obtain user selection
    enumerate(list1, 1)
    choice = input("Choose a movie: ")
    choice1 = list1[int(choice)-1]

    #open txt file for writing
    f = open("test.txt", "x")
    movie = tmdb.Movies(int(choice1))
    response1 = movie.info()
    #print(response1)

    #iterate over list of dictionaries to write chosen data to txt file
    for t in search.results:
        if t['id'] == choice1:
            imdb_url = "https://www.imdb.com/title/" + movie.imdb_id
            f.write(imdb_url + "\n\n")
            poster_url = "https://image.tmdb.org/t/p/original" + str(t['poster_path'])
            f.write(poster_url + "\n" + "\n")
            title = str(t['title']) + " " + (str(t['release_date']))
            f.write(title + "\n" + "\n")
            f.write(response1['tagline'] + "\n\n")
            f.write(t['overview'] + "\n\n")
            tmdb_id = "TMDB ID: " + str(t['id'])
            f.write(tmdb_id + "\n\n")

    f.close()

    #did it work?
    print("Success!")

tmdb_search('life')
Reply
#2
You're not supposed to provide the query as a positional argument, but as a named argument.

Instead of search.movie(query), do search.movie(query=query)
Reply
#3
Thanks for your help. I should be able to review how this works in the search class of tmdbsimple, correct?
Reply
#4
I would normally just look at the documentation for it, but yes you should be able to see this in the method's call signature.

lib/python3.6/site-packages/tmdbsimple/search.py has:

    def movie(self, **kwargs):
        """
        Search for movies.

        Args:
            language: (optional) (optional) ISO 639-1 code.
            query: (required) Pass a text query to search. This value should be
                URI encoded.
            page: (optional) Minimum 1, maximum 1000, default 1.
            include_adult: (optional) Choose whether to inlcude adult
                (pornography) content in the results.
            region: (optional) Specify a ISO 3166-1 code to filter release
                dates. Must be uppercase.
            year: (optional) A filter to limit the results to a specific year
                (looking at all release dates).
            primary_release_year: (optional) A filter to limit the results to a
                specific primary release year.

        Returns:
            A dict respresentation of the JSON returned from the API.
        """
**kwargs consumes any keyword arguments, but the only positional argument is for the reference object.
Reply
#5
Ah yes. This makes sense now. Thanks for helping me figure out how to figure out what's wrong.

**kwargs were starting to make sense before this but connecting them to what I'm trying to practically do helps so much!

This is the kind of thing I'll remember when I start writing classes and methods. Thanks again!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tmdbsimple content type? How to work with it? pythonnewbie138 1 1,416 Aug-01-2020, 08:18 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020