MCPcopy Index your code
hub / github.com/kubernetes-client/python / request

Method request

kubernetes/client/rest.py:108–242  ·  view source on GitHub ↗

Perform requests. :param method: http request method :param url: http request url :param query_params: query parameters in the url :param headers: http request headers :param body: request json body, for `application/json` :param post_params: request

(self, method, url, query_params=None, headers=None,
                body=None, post_params=None, _preload_content=True,
                _request_timeout=None)

Source from the content-addressed store, hash-verified

106 )
107
108 def request(self, method, url, query_params=None, headers=None,
109 body=None, post_params=None, _preload_content=True,
110 _request_timeout=None):
111 """Perform requests.
112
113 :param method: http request method
114 :param url: http request url
115 :param query_params: query parameters in the url
116 :param headers: http request headers
117 :param body: request json body, for `application/json`
118 :param post_params: request post parameters,
119 `application/x-www-form-urlencoded`
120 and `multipart/form-data`
121 :param _preload_content: if False, the urllib3.HTTPResponse object will
122 be returned without reading/decoding response
123 data. Default is True.
124 :param _request_timeout: timeout setting for this request. If one
125 number provided, it will be total request
126 timeout. It can also be a pair (tuple) of
127 (connection, read) timeouts.
128 """
129 method = method.upper()
130 assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT',
131 'PATCH', 'OPTIONS']
132
133 if post_params and body:
134 raise ApiValueError(
135 "body parameter cannot be used with post_params parameter."
136 )
137
138 post_params = post_params or {}
139 headers = headers or {}
140
141 timeout = None
142 if _request_timeout:
143 if isinstance(_request_timeout, six.integer_types + (float, )): # noqa: E501,F821
144 timeout = urllib3.Timeout(total=_request_timeout)
145 elif (isinstance(_request_timeout, tuple) and
146 len(_request_timeout) == 2):
147 timeout = urllib3.Timeout(
148 connect=_request_timeout[0], read=_request_timeout[1])
149
150 if 'Content-Type' not in headers:
151 headers['Content-Type'] = 'application/json'
152
153 try:
154 # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
155 if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
156 if query_params:
157 url += '?' + urlencode(query_params)
158 if (re.search('json', headers['Content-Type'], re.IGNORECASE) or
159 headers['Content-Type'] == 'application/apply-patch+yaml'):
160 if headers['Content-Type'] == 'application/json-patch+json':
161 if not isinstance(body, list):
162 headers['Content-Type'] = \
163 'application/strategic-merge-patch+json'
164 request_body = None
165 if body is not None:

Callers 7

GETMethod · 0.95
HEADMethod · 0.95
OPTIONSMethod · 0.95
DELETEMethod · 0.95
POSTMethod · 0.95
PUTMethod · 0.95
PATCHMethod · 0.95

Calls 10

ApiValueErrorClass · 0.90
ApiExceptionClass · 0.90
ForbiddenExceptionClass · 0.90
NotFoundExceptionClass · 0.90
ServiceExceptionClass · 0.90
RESTResponseClass · 0.70
searchMethod · 0.45
formatMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected