
- Python - Network Programming
- Python - Network Introduction
- Python - Network Environment
- Python - Internet Protocol
- Python - IP Address
- Python - DNS Lookup
- Python - Routing
- Python - HTTP Requests
- Python - HTTP Response
- Python - HTTP Headers
- Python - Custom HTTP Requests
- Python - Request Status Codes
- Python - HTTP Authentication
- Python - HTTP Data Download
- Python - Connection Re-use
- Python - Network Interface
- Python - Sockets Programming
- Python - HTTP Client
- Python - HTTP Server
- Python - Building URLs
- Python - WebForm Submission
- Python - Databases and SQL
- Python - Telnet
- Python - Email Messages
- Python - SMTP
- Python - POP3
- Python - IMAP
- Python - SSH
- Python - FTP
- Python - SFTP
- Python - Web Servers
- Python - Uploading Data
- Python - Proxy Server
- Python - Directory Listing
- Python - Remote Procedure Call
- Python - RPC JSON Server
- Python - Google Maps
- Python - RSS Feed
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Request 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.
import urllib3 http = urllib3.PoolManager() resp = http.request('GET', 'http://tutorialspoint.com/robots.txt') print resp.data # get the status of the response print resp.status
When we run the above program, we get the following output −
User-agent: * Disallow: /tmp Disallow: /logs Disallow: /rate/* Disallow: /cgi-bin/* Disallow: /videotutorials/video_course_view.php?* Disallow: /videotutorials/course_view.php?* Disallow: /videos/* Disallow: /*/*_question_bank/* Disallow: //*/*/*/*/src/* 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 403.
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
When we run the above program, we get the following output −
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /robot.txt on this server.</p> </body></html> 403