session.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:jsonapi-client 作者: qvantel 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号