Introduction
In web development and daily web browsing, we often encounter various HTTP status codes. These status codes are responses from the server to client requests, providing important information about the request processing status. Below, we will introduce some common HTTP status codes and demonstrate their applications through code examples.

1. Informational Status Codes (1xx)
These status codes indicate that the request has been received by the server and is being processed. Common 1xx status codes include:
- • 100 Continue: The server has received the initial part of the request and expects the client to continue sending the rest of the request.
- • 101 Switching Protocols: The server understands and agrees to the client’s request to switch protocols.
2. Successful Status Codes (2xx)
These status codes indicate that the request has been successfully processed. The most common successful status code is:
- • 200 OK: The request has been successfully processed, and the resource has been returned.
import requests
url = "https://example.com"
response = requests.get(url)
if response.status_code == 200:
print("Request successful, resource returned.")
- • 201 Created: The request has been successfully processed, and the server has created a new resource.
- • 204 No Content: The request has been successfully processed, but no content has been returned.
3. Redirection Status Codes (3xx)
These status codes indicate that the client needs to perform specific actions to complete the request. Common redirection status codes include:
- • 301 Moved Permanently: The requested resource has been permanently moved to a new location.
- • 302 Found: The requested resource has temporarily moved to another location.
- • 304 Not Modified: The requested resource has not been modified; the client can use the cached version.
import requests
url = "https://example.com/old"
response = requests.get(url)
if response.status_code == 301:
print(f"Resource has been permanently moved to: {response.headers['Location']}")
4. Client Error Status Codes (4xx)
These status codes indicate that there is an error with the client request, and the server cannot process it. Common client error status codes include:
- • 400 Bad Request: The request cannot be understood by the server, usually due to syntax errors.
- • 401 Unauthorized: The request requires user authentication.
- • 403 Forbidden: The server refuses to execute the request.
- • 404 Not Found: The server cannot find the requested resource.
import requests
url = "https://example.com/unknown"
response = requests.get(url)
if response.status_code == 404:
print("The requested resource does not exist.")
5. Server Error Status Codes (5xx)
These status codes indicate that the server encountered an error while processing the request. Common server error status codes include:
- • 500 Internal Server Error: The server encountered an unexpected condition that prevented it from fulfilling the request.
- • 502 Bad Gateway: The server received an invalid response from the upstream server while acting as a gateway or proxy.
- • 503 Service Unavailable: The server is currently unable to handle the request, usually due to overload or maintenance.
import requests
url = "https://example.com/error"
response = requests.get(url)
if response.status_code == 500:
print("Internal server error, unable to process the request.")
By understanding these common HTTP status codes, we can better comprehend and handle various situations in web requests. In actual development, correctly handling these status codes is crucial for building robust web applications.