1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to APIs in Python

Connected

Exercise

Response codes and APIs

When a client sends a request to a server, the server response includes a numeric status code, which is used to tell the client how the server responded to the request.

In this exercise you will learn about the most important status codes you should know. We will send requests to valid and invalid paths and learn how we can access the status code to determine if our request was successful or not.

The requests package comes with a built-in status code lookup object requests.codes you can use when you don't remember the exact numerical values.

The requests package has been imported for you.

Instructions 1/3

undefined XP
  • 1
    • Check if the server responded successfully with the 200 status code.
  • 2
    • Perform a request to the inexistent /movies path of the music catalog API.
    • Check if the server responded with a status code indicating the resource was not found, providing the appropriate numerical status code representing this.
  • 3
    • Check for response codes with a 200 OK and 404 Not found status code using the requests.codes lookup object.