Imdbpy problem, keyerrors

Hello everyone, I 'm new to coding and I’m trying to do my first project. I’m using imdbpy. Sometimes the code is working just fine and the other times I get keyerrors even though the code is the same. I have read somewhere that imdbpy is not working right so I wanted to check if thats true (otherwise I’m doing something wrong and that is really possible as well haha) and is it better to use imdb api. Thanks :slight_smile:

Hi @juli.poc ,
Perhaps we could be more helpful if you could post your code and what it is that you are trying to achieve in your project. We have no idea of knowing what caused the keyerror without looking at the code. Thanks and have a good day! :slight_smile:

I’m trying to make movie search app. This code gives me nameerror for variables movie, movie_two and movie_three.
It stopped giving me keyerrors but now sometimes gives me undefined error: object has no atribute “plot”. I should probably make a condition what to do if there is no plot atribute.
I suppose this is not the best way of doing things so I would appreciate your advice if you have any. And thanks for your help!

Here is my code:

from flask import Flask, render_template, request
from imdb import IMDb

app = Flask(__name__)

@app.route("/", methods=["POST", "GET"])
def home():
    global movie, movie_two, movie_three
    if request.method == "POST":
        instance = IMDb()
        search = request.form.get("name")
        movie = instance.search_movie(search)

        movie_three = []

        for i in range(len(movie)):
            id_number = movie[i].movieID
            movie_two = instance.get_movie(id_number)

    return render_template("home.html", movie=movie, movie_two=movie_two, movie_three=movie_three)

if __name__ == "__main__":


{% extends "base.html" %}
{% block content%}
<div align="center" >
    <h1>Something To Watch</h1>
    <div class="container">
        <form class="search" action="{{url_for('home')}}" method="post">
            <input type="search" placeholder="Type here..." name="name" >
            <button type="submit" value="submit">Search</button>

{% for m in movie_three %}
<div class="row">
    <div  align="center" class="card" style="width: 15rem;">
        <img class="card-img-top" src={{m["cover"]}} alt="Card image cap">
        <div class="card-body">
            <h5 class="card-title">{{m["title"]}}</h5>
            <h6 class="card-subtitle mb-2 text-muted">{{m["year"]}}</h6>
            <h6 class="card-subtitle mb-2 text-muted">{{m["kind"]}} - {{m["genres"]}}</h6>
            <h6 class="card-subtitle mb-2 text-muted">{{m["rating"]}}</h6>
            <p class="card-text">{{m["plot"][0]}}</p>

            <a href=# class="card-link">Go to IMDb</a>
            <a href="{{url_for('home')}}" class="card-link">Homepage</a>

{% endblock %}