Requests Module
1. Module description
Requests is an HTTP library that uses Apache2 Licensed licenses. Written in Python, really for the sake of mankind.
The urllib2 module in the Python Standard library provides most of the HTTP functionality you need, but its API is too slag-off. It was created for another era, another internet. It requires a huge amount of work, even covering a variety of methods, to accomplish the simplest task.
In Python's world, things shouldn't be so troublesome.
Requests uses URLLIB3, so it inherits all of its features. Requests supports HTTP connection retention and connection pooling, supports the use of cookies to maintain sessions, supports file uploads, supports automatic encoding of response content, supports internationalized URLs and automatic POST data encoding. Modern, international, humane.
(The above is transferred from requests official documents)
2. Module installation
PIP Install requests
Try to import requests in the IDE, if there is no error, then the installation is successful.
3, Simple first knowledge
from Import View class Index (View): def get (self, request): Print (Request.method) return HttpResponse ('requests module Test ')
views.py
Send request:
Import requestsresponse = Requests.get (' http://127.0.0.1:8000/index/') #发送get请求print (response.text) # String type print (response.content) #bytes类型 # requests Module Test # <class ' bytes ' >
Python development "modules": Requests