Python development "modules": Requests

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.