Execute request :param method: http request method :param url: http request url :param headers: http request headers :param body: request json body, for `application/json` :param post_params: request post parameters, `application/x
(
self,
method,
url,
headers=None,
body=None,
post_params=None,
_request_timeout=None)
| 76 | await self.pool_manager.aclose() |
| 77 | |
| 78 | async def request( |
| 79 | self, |
| 80 | method, |
| 81 | url, |
| 82 | headers=None, |
| 83 | body=None, |
| 84 | post_params=None, |
| 85 | _request_timeout=None): |
| 86 | """Execute request |
| 87 | |
| 88 | :param method: http request method |
| 89 | :param url: http request url |
| 90 | :param headers: http request headers |
| 91 | :param body: request json body, for `application/json` |
| 92 | :param post_params: request post parameters, |
| 93 | `application/x-www-form-urlencoded` |
| 94 | and `multipart/form-data` |
| 95 | :param _request_timeout: timeout setting for this request. If one |
| 96 | number provided, it will be total request |
| 97 | timeout. It can also be a pair (tuple) of |
| 98 | (connection, read) timeouts. |
| 99 | """ |
| 100 | method = method.upper() |
| 101 | assert method in [ |
| 102 | 'GET', |
| 103 | 'HEAD', |
| 104 | 'DELETE', |
| 105 | 'POST', |
| 106 | 'PUT', |
| 107 | 'PATCH', |
| 108 | 'OPTIONS' |
| 109 | ] |
| 110 | |
| 111 | if post_params and body: |
| 112 | raise ApiValueError( |
| 113 | "body parameter cannot be used with post_params parameter." |
| 114 | ) |
| 115 | |
| 116 | post_params = post_params or {} |
| 117 | headers = headers or {} |
| 118 | timeout = _request_timeout or 5 * 60 |
| 119 | |
| 120 | if 'Content-Type' not in headers: |
| 121 | headers['Content-Type'] = 'application/json' |
| 122 | |
| 123 | args = { |
| 124 | "method": method, |
| 125 | "url": url, |
| 126 | "timeout": timeout, |
| 127 | "headers": headers |
| 128 | } |
| 129 | |
| 130 | # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` |
| 131 | if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: |
| 132 | if re.search('json', headers['Content-Type'], re.IGNORECASE): |
| 133 | if body is not None: |
| 134 | args["json"] = body |
| 135 | elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501 |