您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“一些有用的編程參數(shù)說明”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“一些有用的編程參數(shù)說明”吧!
def request(method, url, **kwargs): """Constructs and sends a :class:`Request <Request>`. :param method: method for the new :class:`Request` object. method用于將要創(chuàng)建的類Requet的參數(shù),get,post之類. :param url: URL for the new :class:`Request` object. 傳入Request的URL參數(shù),即訪問的網(wǎng)頁,一般需要帶有完整的協(xié)議,而不是簡單的域名. :param params: (optional) Dictionary, list of tuples or bytes to send in the body of the :class:`Request`. 字典類型或者是tuple集合或者byte類型 params是參數(shù),也就是 ?key=value&key=value&... 也就是鏈接后面的. 也可以通過 [(key,value)] 也可以是直接按照http協(xié)議編碼好的數(shù)據(jù) :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. data 字典類型或者是tuple集合或者byte類型或者是一個文件一樣的類 一般是表單中的數(shù)據(jù). :param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`. 對應(yīng)調(diào)試程序中的 request payload json,序列化發(fā)送過去的數(shù)據(jù) :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. 請求頭,包括許多的格式和標準還有參數(shù)信息等等。字典或者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. 授權(quán) :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 設(shè)置超時,等待服務(wù)器多少秒后就放棄發(fā)送??梢允莊loat或者是一個元組,分別是連接和響應(yīng)超時時長 :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. 代理,可以設(shè)置多個代理。 :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值就是控制是否給證書,如果是一個字符串就是整數(shù)存放的位置。默認是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. 聲明授權(quán)文件,一般用于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會被關(guān)閉。避免離開sockets導(dǎo)致了錯誤,比如其他地方內(nèi)存益處。 with sessions.Session() as session: return session.request(method=method, url=url, **kwargs)
到此,相信大家對“一些有用的編程參數(shù)說明”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。