- Python Network Programming - Home
- Python Network Introduction
- Python Networking - Environment Setup
- Python Networking - Internet Protocol
- Python Networking - IP Address
- Python Networking - DNS Lookup
- Python Networking - Routing
- Python Networking - HTTP Requests
- Python Networking - HTTP Response
- Python Networking - HTTP Headers
- Python Networking - Custom HTTP Requests
- Python Networking - Request Status Codes
- Python Networking - HTTP Authentication
- Python Networking - HTTP Data Download
- Python Networking - Connection Re-use
- Python Networking - Network Interface
- Python Networking - Sockets Programming
- Python Networking - HTTP Client
- Python Networking - HTTP Server
- Python Networking - Building URLs
- Python Networking - WebForm Submission
- Python Networking - Databases and SQL
- Python Networking - Telnet
- Python Networking - Email Messages
- Python Networking - SMTP
- Python Networking - POP3
- Python Networking - IMAP
- Python Networking - SSH
- Python Networking - FTP
- Python Networking - SFTP
- Python Networking - Web Servers
- Python Networking - Uploading Data
- Python Networking - Proxy Server
- Python Networking - Directory Listing
- Python Networking - Remote Procedure Call
- Python Networking - RPC JSON Server
- Python Networking - Google Maps
- Python Networking - RSS Feed
Python Network Programming Resources
Python Network - Status Codes
After receiving and interpreting a request message, a server responds with an HTTP response message. The response message has a Status-Code. It is a 3-digit integer where first digit of the Status-Code defines the class of response and the last two digits do not have any categorization role. There are 5 values for the first digit:
Status Codes
| S.N. | Code and Description |
|---|---|
| 1 | 1xx: Informational It means the request was received and the process is continuing. |
| 2 | 2xx: Success It means the action was successfully received, understood, and accepted. |
| 3 | 3xx: Redirection It means further action must be taken in order to complete the request. |
| 4 | 4xx: Client Error It means the request contains incorrect syntax or cannot be fulfilled. |
| 5 | 5xx: Server Error It means the server failed to fulfill an apparently valid request. |
Successful Response
In the below example we access a file from a url and the response is successful. So the status code returned is 200.
main.py
import urllib3
http = urllib3.PoolManager()
resp = http.request('GET', 'https://tutorialspoint.com/robots.txt')
print(resp.data)
# get the status of the response
print(resp.status)
Output
When we run the above program, we get the following output −
b'# This file is being served by CloudFront, please check listed behaviours. ... Disallow: /listtutorials/ ... 200
Unsuccessful Response
In the below example we access a file from a url which does not exist. The response is unsuccessful. So the status code returned is 404.
main.py
import urllib3
http = urllib3.PoolManager()
resp = http.request('GET', 'http://tutorialspoint.com/robot.txt')
print(resp.data)
# get the status of the response
print(resp.status)
Output
When we run the above program, we get the following output −
b'<... <head>\n<title>404 Not Found</title> ... 404