def http_request_async(
self,
http_method: str,
url: str,
send_json: dict,
expected_statuses: List[str]=None) \
-> Tuple[int, dict, str]:
"""
Internal use. Async version.
Method to make PATCH/POST requests to server using aiohttp library.
"""
self.assert_async()
logger.debug('%s request: %s', http_method.upper(), send_json)
expected_statuses = expected_statuses or HttpStatus.ALL_OK
content_type = '' if http_method == HttpMethod.DELETE else 'application/vnd.api+json'
async with self._aiohttp_session.request(
http_method, url, data=json.dumps(send_json),
headers={'Content-Type':'application/vnd.api+json'},
**self._request_kwargs) as response:
if response.status not in expected_statuses:
raise DocumentError(f'Could not {http_method.upper()} '
f'({response.status}): '
f'{error_from_response(response)}',
errors={'status_code': response.status},
response=response,
json_data=send_json)
response_json = await response.json(content_type=content_type)
return response.status, response_json or {}, response.headers.get('Location')
评论列表
文章目录