import urllib.request
url = 'http://www.baidu.com/'
# Let's customize a request and the corresponding response he is a class object HttpResponse
response = urllib.request.urlopen (url)
The # 6 substantially have the following respective processing mode
# 1 returns directly to the entire page in binary format
Print (response.read ())
# 2. returns to give the binary format to obtain the first row have a page
print (response.readline ())
# 3. return all data in binary format was saved in a list format
Print (response.readlines ())
# 4. Gets the status code --200 representatives have to be a server response to a successful test we have to add this line of code to determine the habit whether successful return
Print (response.getcode ())
# 5. The acquisition response header
Print (response.getheaders ())
# 6. The Get URL
Print (response.geturl ())
Finally, attach a series of common status codes
Status Code farming | Explanation | Detail |
100 | carry on | Requestor should continue with the request, the server has received part of the request |
101 | Switching Protocol | The requester has requested a handover protocol server, and the server is ready to switch confirmed |
200 | success | The server has successfully processed the request (this is everyone's favorite see ~~) |
201 | Has been created | Request was successful and the server created a new resource |
202 | accepted | However, the service request has been accepted, but not yet processed |
203 | Unauthorized information | The server successfully processed the request, but is returning information that may come from another source |
204 | No content | Server successfully processed the request, but is not returning any content |
205 | Reset Content | Server successfully processed the request, the content should be re |
206 | Part | Server successfully processed a partial request |
300 | multiple choices | For the request, the server has several actions |
301 | Moved Permanently | Permanently requested page has been moved to a new location, i.e. permanent redirection |
302 | l Temporary Mobile | The requested page is temporarily jump to other pages that temporarily re |
303 | View other locations | If the original request was POST, GET redirect target document should be extracted by |
304 | Unmodified | The request returns web pages unmodified, continue to use the last resources |
305 | Use a proxy | Requester should use a proxy to access the page |
307 | Temporary Redirect | In response to a temporary resource request from another location l |
400 | Error versed in demand | The server can not resolve the request |
401 | unauthorized | Authentication request does not pass the authentication or |
403 | No Access | Services will reject this request |
404 | Not found | Web server can not find the requested |
405 | Methods disabled | Disable the server method specified in the request |
406 | Does not accept | You can not use the content of the request in response to the request page |
407 | The right to require proxy search | Requester need to use proxy authorization |
408 | Request timed out | Server request timed out |
409 | conflict | Server encountered a conflict fulfilling the request |
410 | deleted | Requested resource has been permanently removed |
411 | Length required | Server will not accept without a valid Content-Length header field of the request |
412 | Precondition Failed | Wherein the server is not a prerequisite for the requestor in the request satisfies |
413 | Request Entity Too Large | Requesting entity is too large, exceeding the server's processing capability |
414 | Request URI is too long | Request URL is too long, the server can not handle |
415 | Type is not supported | Request format does not support the requested page |
416 | Request does not match the range | Page unable to provide the requested range |
417 | Surgery to meet expectations | Server can not meet the desired requirements of the request header field |
500 | Internal server error | The server encountered an error and can not fulfill the request |
501 | Unrealized | The server does not have to complete the requested function |
502 | Bad Gateway | As a gateway or proxy server received an invalid response from the upstream service then |
503 | service is not available | Server is currently unavailable |
504 | Gateway Timeout | As a gateway or proxy server, but did not receive a timely request from the upstream service ~~ |
505 | HTTP version not supported | The server does not support the HTTP protocol version used in the request |