MCPcopy
hub / github.com/psf/requests / request

Function request

src/requests/api.py:24–71  ·  view source on GitHub ↗

Constructs and sends a :class:`Request <Request>`. :param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary, list of t

(
    method: str, url: _t.UriType, **kwargs: Unpack[_t.RequestKwargs]
)

Source from the content-addressed store, hash-verified

22
23
24def request(
25 method: str, url: _t.UriType, **kwargs: Unpack[_t.RequestKwargs]
26) -> Response:
27 """Constructs and sends a :class:`Request <Request>`.
28
29 :param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
30 :param url: URL for the new :class:`Request` object.
31 :param params: (optional) Dictionary, list of tuples or bytes to send
32 in the query string for the :class:`Request`.
33 :param data: (optional) Dictionary, list of tuples, bytes, or file-like
34 object to send in the body of the :class:`Request`.
35 :param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
36 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
37 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
38 :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
39 ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
40 or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content_type'`` is a string
41 defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
42 to add for the file.
43 :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
44 :param timeout: (optional) How many seconds to wait for the server to send data
45 before giving up, as a float, or a :ref:`(connect timeout, read
46 timeout) <timeouts>` tuple.
47 :type timeout: float or tuple
48 :param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.
49 :type allow_redirects: bool
50 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
51 :param verify: (optional) Either a boolean, in which case it controls whether we verify
52 the server&#x27;s TLS certificate, or a string, in which case it must be a path
53 to a CA bundle to use. Defaults to ``True``.
54 :param stream: (optional) if ``False``, the response content will be immediately downloaded.
55 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
56 :return: :class:`Response <Response>` object
57 :rtype: requests.Response
58
59 Usage::
60
61 >>> import requests
62 >>> req = requests.request('GET', 'https://httpbin.org/get')
63 >>> req
64 <Response [200]>
65 """
66
67 # By using the 'with' statement we are sure the session is closed, thus we
68 # avoid leaving sockets open which can trigger a ResourceWarning in some
69 # cases, and look like a memory leak in others.
70 with sessions.Session() as session:
71 return session.request(method=method, url=url, **kwargs)
72
73
74def get(

Callers 7

getFunction · 0.85
optionsFunction · 0.85
headFunction · 0.85
postFunction · 0.85
putFunction · 0.85
patchFunction · 0.85
deleteFunction · 0.85

Calls 1

requestMethod · 0.80

Tested by

no test coverage detected