|
def | __init__ (self, configuration, pools_size=4, maxsize=None) |
|
def | request (self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, _request_timeout=None) |
|
def | GET (self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None) |
|
def | HEAD (self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None) |
|
def | OPTIONS (self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, _request_timeout=None) |
|
def | DELETE (self, url, headers=None, query_params=None, body=None, _preload_content=True, _request_timeout=None) |
|
def | POST (self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, _request_timeout=None) |
|
def | PUT (self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, _request_timeout=None) |
|
def | PATCH (self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, _request_timeout=None) |
|
Definition at line 52 of file rest.py.
def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.request |
( |
|
self, |
|
|
|
method, |
|
|
|
url, |
|
|
|
query_params = None , |
|
|
|
headers = None , |
|
|
|
body = None , |
|
|
|
post_params = None , |
|
|
|
_preload_content = True , |
|
|
|
_request_timeout = None |
|
) |
| |
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 post parameters,
`application/x-www-form-urlencoded`
and `multipart/form-data`
:param _preload_content: if False, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Default is True.
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
Definition at line 107 of file rest.py.
109 _request_timeout=
None):
112 :param method: http request method
113 :param url: http request url
114 :param query_params: query parameters in the url
115 :param headers: http request headers
116 :param body: request json body, for `application/json`
117 :param post_params: request post parameters,
118 `application/x-www-form-urlencoded`
119 and `multipart/form-data`
120 :param _preload_content: if False, the urllib3.HTTPResponse object will
121 be returned without reading/decoding response
122 data. Default is True.
123 :param _request_timeout: timeout setting for this request. If one
124 number provided, it will be total request
125 timeout. It can also be a pair (tuple) of
126 (connection, read) timeouts.
128 method = method.upper()
129 assert method
in [
'GET',
'HEAD',
'DELETE',
'POST',
'PUT',
132 if post_params
and body:
134 "body parameter cannot be used with post_params parameter."
137 post_params = post_params
or {}
138 headers = headers
or {}
142 if isinstance(_request_timeout, (int, )
if six.PY3
else (int, long)):
143 timeout = urllib3.Timeout(total=_request_timeout)
144 elif (isinstance(_request_timeout, tuple)
and
145 len(_request_timeout) == 2):
146 timeout = urllib3.Timeout(
147 connect=_request_timeout[0], read=_request_timeout[1])
149 if 'Content-Type' not in headers:
150 headers[
'Content-Type'] =
'application/json'
154 if method
in [
'POST',
'PUT',
'PATCH',
'OPTIONS',
'DELETE']:
156 url +=
'?' + urlencode(query_params)
157 if re.search(
'json', headers[
'Content-Type'], re.IGNORECASE):
160 request_body = json.dumps(body)
161 r = self.pool_manager.request(
164 preload_content=_preload_content,
167 elif headers[
'Content-Type'] ==
'application/x-www-form-urlencoded':
168 r = self.pool_manager.request(
171 encode_multipart=
False,
172 preload_content=_preload_content,
175 elif headers[
'Content-Type'] ==
'multipart/form-data':
179 del headers[
'Content-Type']
180 r = self.pool_manager.request(
183 encode_multipart=
True,
184 preload_content=_preload_content,
190 elif isinstance(body, str):
192 r = self.pool_manager.request(
195 preload_content=_preload_content,
200 msg =
"""Cannot prepare a request message for provided
201 arguments. Please check that your arguments match
202 declared content type."""
203 raise ApiException(status=0, reason=msg)
206 r = self.pool_manager.request(method, url,
208 preload_content=_preload_content,
211 except urllib3.exceptions.SSLError
as e:
212 msg =
"{0}\n{1}".format(
type(e).__name__,
str(e))
213 raise ApiException(status=0, reason=msg)
219 logger.debug(
"response body: %s", r.data)
221 if not 200 <= r.status <= 299:
222 raise ApiException(http_resp=r)