Execute request :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 po
(self, method, url, query_params=None, headers=None,
body=None, post_params=None, _preload_content=True,
_request_timeout=None)
| 89 | await self.pool_manager.close() |
| 90 | |
| 91 | async def request(self, method, url, query_params=None, headers=None, |
| 92 | body=None, post_params=None, _preload_content=True, |
| 93 | _request_timeout=None): |
| 94 | """Execute request |
| 95 | |
| 96 | :param method: http request method |
| 97 | :param url: http request url |
| 98 | :param query_params: query parameters in the url |
| 99 | :param headers: http request headers |
| 100 | :param body: request json body, for `application/json` |
| 101 | :param post_params: request post parameters, |
| 102 | `application/x-www-form-urlencoded` |
| 103 | and `multipart/form-data` |
| 104 | :param _preload_content: this is a non-applicable field for |
| 105 | the AiohttpClient. |
| 106 | :param _request_timeout: timeout setting for this request. If one |
| 107 | number provided, it will be total request |
| 108 | timeout. It can also be a pair (tuple) of |
| 109 | (connection, read) timeouts or object |
| 110 | of aiohttp.ClientTimeout. |
| 111 | """ |
| 112 | method = method.upper() |
| 113 | assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', |
| 114 | 'PATCH', 'OPTIONS'] |
| 115 | |
| 116 | if post_params and body: |
| 117 | raise ApiValueError( |
| 118 | "body parameter cannot be used with post_params parameter." |
| 119 | ) |
| 120 | |
| 121 | post_params = post_params or {} |
| 122 | headers = headers or {} |
| 123 | timeout = aiohttp.ClientTimeout() |
| 124 | if _request_timeout: |
| 125 | if isinstance(_request_timeout, (int, float)): |
| 126 | timeout = aiohttp.ClientTimeout(total=_request_timeout) |
| 127 | elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2: |
| 128 | timeout = aiohttp.ClientTimeout( |
| 129 | connect=_request_timeout[0], |
| 130 | sock_connect=_request_timeout[0], |
| 131 | sock_read=_request_timeout[1], |
| 132 | ) |
| 133 | elif isinstance(_request_timeout, aiohttp.ClientTimeout): |
| 134 | timeout = _request_timeout |
| 135 | |
| 136 | if 'Content-Type' not in headers: |
| 137 | headers['Content-Type'] = 'application/json' |
| 138 | |
| 139 | args = { |
| 140 | "method": method, |
| 141 | "url": url, |
| 142 | "timeout": timeout, |
| 143 | "headers": headers |
| 144 | } |
| 145 | |
| 146 | if self.proxy: |
| 147 | args["proxy"] = self.proxy |
| 148 | if self.proxy_headers: |
no test coverage detected