您好,登錄后才能下訂單哦!
本篇內容主要講解“一些有用的編程參數說明”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“一些有用的編程參數說明”吧!
def request(method, url, **kwargs): """Constructs and sends a :class:`Request <Request>`. :param method: method for the new :class:`Request` object. method用于將要創建的類Requet的參數,get,post之類. :param url: URL for the new :class:`Request` object. 傳入Request的URL參數,即訪問的網頁,一般需要帶有完整的協議,而不是簡單的域名. :param params: (optional) Dictionary, list of tuples or bytes to send in the body of the :class:`Request`. 字典類型或者是tuple集合或者byte類型 params是參數,也就是 ?key=value&key=value&... 也就是鏈接后面的. 也可以通過 [(key,value)] 也可以是直接按照http協議編碼好的數據 :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. data 字典類型或者是tuple集合或者byte類型或者是一個文件一樣的類 一般是表單中的數據. :param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`. 對應調試程序中的 request payload json,序列化發送過去的數據 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. 請求頭,包括許多的格式和標準還有參數信息等等。字典或者http Headers :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. cookies可以放入headers中也可以手動添加。可以是字典,cookiejar對象 :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload. 字典或者多個傳輸模塊的方式。 ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` file-tuple可以是兩個元素或者是三個元素的元組,或者是四個元素的元組 or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers to add for the file. :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. 授權 :param timeout: (optional) How many seconds to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) <timeouts>` tuple. :type timeout: float or tuple 設置超時,等待服務器多少秒后就放棄發送。可以是float或者是一個元組,分別是連接和響應超時時長 :param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``. :type allow_redirects: bool 傳入一個bool值,表示是否允許重定向。 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. 代理,可以設置多個代理。 :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. 如果是一個bool值就是控制是否給證書,如果是一個字符串就是整數存放的位置。默認是True。 空的證書可能會失敗.一般用于訪問`https`報證書錯誤,同下面的 cert :param stream: (optional) if ``False``, the response content will be immediately downloaded. 是按照stream還是直接下載,默認是直接下載,如果我們下載文件,視頻什么的可以通過流下載。 我們可以看一下you-get,當資源太多的時候,就可以用流的形式一點點的讀取. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. 聲明授權文件,一般用于https訪問,比如說報錯 certificate verify failed: unable to get local issuer certificate :return: :class:`Response <Response>` object :rtype: requests.Response Usage:: >>> import requests >>> req = requests.request('GET', 'https://httpbin.org/get') <Response [200]> """ # By using the 'with' statement we are sure the session is closed, thus we # avoid leaving sockets open which can trigger a ResourceWarning in some # cases, and look like a memory leak in others. # 通過with模式我們可以保證session會被關閉。避免離開sockets導致了錯誤,比如其他地方內存益處。 with sessions.Session() as session: return session.request(method=method, url=url, **kwargs)
到此,相信大家對“一些有用的編程參數說明”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。