O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sending a GET request

A GET request allows the requester (often called a client) to receive some information from a server. We can use a GET request to ask our server for some data in JSON format, which we can then use in the rest of the script.

Ensure your flask server is still running, then, open up a new Python file. Add the following content:

import requestsr = requests.get("http://127.0.0.1:5000")data = r.json()print(f"There are {data['people']} people. {data['cats']} of them have a cat, and {data['dogs']} of them have a dog")

In this example, we import the requests module and use it to send a GET request to our server using its get method.

Since our server returns JSON, we can use the json method to parse the result into a Python dictionary, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required