Aug-06-2020, 09:17 PM
(This post was last modified: Aug-07-2020, 03:00 PM by pythonnewbie138.)
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')