Perform requests. :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
(
self,
method,
url,
headers=None,
body=None,
post_params=None,
_request_timeout=None
)
| 113 | self.pool_manager = urllib3.PoolManager(**pool_args) |
| 114 | |
| 115 | def request( |
| 116 | self, |
| 117 | method, |
| 118 | url, |
| 119 | headers=None, |
| 120 | body=None, |
| 121 | post_params=None, |
| 122 | _request_timeout=None |
| 123 | ): |
| 124 | """Perform requests. |
| 125 | |
| 126 | :param method: http request method |
| 127 | :param url: http request url |
| 128 | :param headers: http request headers |
| 129 | :param body: request json body, for `application/json` |
| 130 | :param post_params: request post parameters, |
| 131 | `application/x-www-form-urlencoded` |
| 132 | and `multipart/form-data` |
| 133 | :param _request_timeout: timeout setting for this request. If one |
| 134 | number provided, it will be total request |
| 135 | timeout. It can also be a pair (tuple) of |
| 136 | (connection, read) timeouts. |
| 137 | """ |
| 138 | method = method.upper() |
| 139 | assert method in [ |
| 140 | 'GET', |
| 141 | 'HEAD', |
| 142 | 'DELETE', |
| 143 | 'POST', |
| 144 | 'PUT', |
| 145 | 'PATCH', |
| 146 | 'OPTIONS' |
| 147 | ] |
| 148 | |
| 149 | if post_params and body: |
| 150 | raise ApiValueError( |
| 151 | "body parameter cannot be used with post_params parameter." |
| 152 | ) |
| 153 | |
| 154 | post_params = post_params or {} |
| 155 | headers = headers or {} |
| 156 | |
| 157 | timeout = None |
| 158 | if _request_timeout: |
| 159 | if isinstance(_request_timeout, (int, float)): |
| 160 | timeout = urllib3.Timeout(total=_request_timeout) |
| 161 | elif ( |
| 162 | isinstance(_request_timeout, tuple) |
| 163 | and len(_request_timeout) == 2 |
| 164 | ): |
| 165 | timeout = urllib3.Timeout( |
| 166 | connect=_request_timeout[0], |
| 167 | read=_request_timeout[1] |
| 168 | ) |
| 169 | |
| 170 | try: |
| 171 | # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` |
| 172 | if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: |
no test coverage detected