python requets 参数说明

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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章