Python's Library requests tutorial

Source: Internet
Author: User

Requests is a third-party library of Python, claiming:
Requests:http for humans
Quick Chinese Tutorial in this: http://cn.python-requests.org/zh_CN/latest/
After reading a little puzzled, do not know how to use, looked at the source, found
#官冈文档中第一条就是
>>> r = requests.get (' Https://github.com/timeline.json ')
>>> r = requests.put ("Http://httpbin.org/put")
>>> r = Requests.delete ("Http://httpbin.org/delete")
>>> r = Requests.head ("Http://httpbin.org/get")
>>> r = requests.options ("Http://httpbin.org/get")


#实际定义是 (in api.py):
Def request (method, URL, **kwargs):
def get (URL, **kwargs):
... code goes here ...
Return request (' Get ', URL, **kwargs):

Several other functions are the same call requests ()
Where the requests function parameter description:

"" "Constructs and sends A:class: ' Request <Request> '.
Returns:class: ' Response <Response> ' object.

:p Aram Method:method for the New:class: ' Request ' object.
:p Aram Url:url for the New:class: ' Request ' object.
:p Aram params: (optional) Dictionary or bytes to being sent in the query string for the:class: ' Request '.
:p Aram Data: (optional) Dictionary, Bytes, or File-like object to send in the body of The:class: ' Request '.
:p Aram JSON: (optional) JSON data to send in the body of The:class: ' Request '.
:p Aram Headers: (optional) Dictionary of HTTP headers to send with The:class: ' Request '.
:p Aram Cookies: (optional) Dict or Cookiejar object to send with The:class: ' Request '.
:p Aram Files: (optional) Dictionary of ' name ': File-like-objects ' (or ' {' name ': (' filename ', fileobj)} ') for Multipar T encoding upload.
:p Aram Auth: (optional) auth tuple to enable Basic/digest/custom HTTP auth.
:p Aram Timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a (' Connect Timeo UT, read timeout <user/advanced.html#timeouts> ' _) tuple.
: Type Timeout:float or tuple
:p Aram Allow_redirects: (optional) Boolean. Set to True if Post/put/delete redirect following is allowed.
: Type Allow_redirects:bool
:p Aram proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
:p Aram Verify: (optional) if ' True ', the SSL cert would be verified. A Ca_bundle Path can also be provided.
:p Aram Stream: (optional) if ' False ', the response content would be immediately downloaded.
:p Aram cert: (optional) if String, path to SSL client cert file (. pem). If Tuple, (' cert ', ' key ') pair.


"""

The requests function uses the keyword parameter (**kwargs): The keyword parameter allows you to pass in 0 or any parameter with parameter names that are automatically assembled inside the function as a dict. Defining functions in Python can be done with required parameters, default parameters, variable parameters, and keyword parameters, all of which can be used together, or only some of them, but note that the order of the parameters definition must be: required, default, variable, and keyword parameters. 4

Python's Library requests tutorial

Related Article

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.