Python program for searching books returns googleapis.com:443

17 views
Skip to first unread message

Arnon Rodrigues

unread,
Jun 4, 2021, 4:08:40 PM6/4/21
to Google Visualization API
Hi, I have a Python program where you can create your own bookshelf. Database and everything are working fine, everything is almost done. But I noticed that there are some books (durinthe search) that loads forever and Terminal returns me (infinite times):
```
DEBUG: https://www.googleapis.com:443 "GET /books/v1/volumes?q=moby%20dick HTTP/1.1" 200 None
DEBUG: Starting new HTTPS connection (1): www.googleapis.com:443
```

Here is my code:
Captura de Tela 2021-06-04 às 17.02.52.png
@app.route('/search', methods=["GET", "POST"])
@login_required
def search():
    if request.method == "POST":
        while True:
            try:
                seek = request.form.get("seek")
                response = requests.get(url)
                response.raise_for_status()
                search = response.json()
                seek = search['items']
                infobooks = []
                    for i in range(len(seek)):
                        infobooks.append({
                            "book_id": seek[i]['id'],
                            "thumbnail": seek[i]['volumeInfo']['imageLinks']['thumbnail'],
                            "title": seek[i]['volumeInfo']['title'],
                            "authors": seek[i]['volumeInfo']['authors']
                    })
                return render_template("index.html", infobooks = infobooks)
            except (requests.RequestException, KeyErrorTypeErrorValueError):
                continue
    else:
        return render_template("index.html")

After this, I just display the result in the HTML by doing this:
Captura de Tela 2021-06-04 às 17.04.47.png

The final result is very beautiful, mainly when it works:
Captura de Tela 2021-06-04 às 17.06.12.png

The problem occurs when I search for a book with two names like "Harry Potter" or "Moby Dick", but it sometimes it occurs with one name too.

Does anyone could help me?

Thanks in advance!
Reply all
Reply to author
Forward
0 new messages