The Movie Database Support

I'm building a program that retrieves the poster of a movie or TV from a list of titles. For some reason, about 50% of the titles my program searches return no results when searched but when I use the exact same terms that my program is using on the actual website, it shows the exact results I'm looking for. Note that these titles are consistent and the response code to the query is always 200. Does anyone have any insight?

Some titles that return nothing: MH370: The Plane That Disappeared, Waco: American Apocalypse, I Am Georgina

Here's my code:

import requests

api_key = "key"
base_url = "https://api.themoviedb.org/3"
headers = {"Authorization": f"Bearer {api_key}"}

title = "title of show or movie"

queryDB = title
params = {
    "api_key": api_key,
    "query": queryDB,
    "language": "en-US",
    "include_adult": False
}

# Make request to search for movie
response = requests.get(f"{base_url}/search/movie", headers=headers, params=params)
response.raise_for_status()  # Raise exception if request fails

# Get first result from search
results = response.json()["results"]
if not results:
    # No results found for search query
    poster_url = None
    print("no results found")
else:
    # Get poster image URL from movie details
    movie_id = results[0]["id"]
    response = requests.get(f"{base_url}/movie/{movie_id}", headers=headers, params=params)
    response.raise_for_status()  # Raise exception if request fails
    poster_url = f"https://image.tmdb.org/t/p/original{response.json()['poster_path']}"

2 replies (on page 1 of 1)

Jump to last post

Did you URI encode your search string ? https://developers.themoviedb.org/3/search/search-movies

@superboy97 said:

Did you URI encode your search string ? https://developers.themoviedb.org/3/search/search-movies

I didn't at the time but I rewrote my code to do just that. I'm still getting no results found. I used the "try it out" tab here https://developers.themoviedb.org/3/search/search-movies to generate an encoded URL that I could compare my encoded URL to and they match. I'd share my code but for some reason the site won't let me post it.

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login