MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Introduction to APIs in Python

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

response = requests.get('http://localhost:3000/lyrics')

# Check the response status code
if (response.____ == ____):
  print('The server responded succesfully!')
Edit dan Jalankan Kode