Reptile request library

reponse object properties:
r.status_code HTTP request returns a status 200 indicates successful connection, 404 represents a failure
String r.text HTTP response content, i.e., url corresponding page content
Encoding r.encoding response content from the HTTP header of the guess
r.apparent_encoding from a content analysis of the response content encoding
r.content HTTP response to the binary form of the content
 
 
request database connection exception
requests.ConnectionError network connection error exceptions, such as DNS query failed, refused connections
requests.HTTPError HTTP error exception
requests.URLRequired URL missing abnormal
requests.TooManyRedicects exceed the maximum number of redirects, redirect produce abnormal
requests.ConnectTimeout connect to a remote server timeout exception
requests.Timeout URL request timeout, a timeout exception
requests.raise_for_status () if not 200, an abnormality requests.HTTPError
 
 
request library seven main methods:
requests.request () Constructs a request, the following method of supporting foundation method
        requests.request(method,url,**kwargs)
            method: request method, the corresponding get / put / post / options such as seven kinds
            url: url intends to get links to pages
            ** kwargs: access control parameters, a total of 13
                    params: byte dictionary or a sequence, as a parameter added to the url
                    data: dictionary, a sequence of bytes or a file object, as the contents of the Request
                    json: JSON-formatted data, as content Request
                    headers: dictionary, HTTP custom header (Analog browser initiating access to the site)
                    cookies: a dictionary or CookieJar, Request of cookie
                    auth: tuples, support HTTP authentication
                    files: a dictionary, file transfer
                    timeout: set the timeout, seconds
                    proxies: a dictionary, set the access proxy server, you can increase the login agent
                    allow_redirects: True / False, the default True, switch redirects
                    stream: True / False, the default is True, immediately switch access to content download
                    verify: True / False, the default is True, SSL certificate authentication switch
                    cert: Local SSL certificate path
requests.get () method to get the main HTML page corresponding to the HTML GET
         requests.get(url,params=None,**kwargs)
requests.head () Gets a method HTML page header information corresponding to the HTML HEAD
         requests.head(url,**kwargs) 
Method requests.post () POST request to submit HTML page corresponding to the HTML POST (append new data)
        requests.post(url,data=None,json=None,**kwargs)
Method requests.put () PUT request submitted to the HTML page corresponding to the HTML PUT (cover original storage resources)
        requests.put(url,data=None,**kwargs)
requests.patch () to submit a request to the local modification of the HTML page corresponding to the HTML PATCH
         requests.patch(url,data=None,**kwargs)
requests.delete () to submit a request to the HTML page corresponding to the HTML DELETDE
         requests.delete(url,**kwargs)
 
 
 
 

Guess you like

Origin www.cnblogs.com/carrotmvp/p/12302570.html
Recommended