def http_request(self, http_method: str, url: str, send_json: dict,
expected_statuses: List[str]=None) -> Tuple[int, dict, str]:
"""
Internal use.
Method to make PATCH/POST requests to server using requests library.
"""
self.assert_sync()
import requests
logger.debug('%s request: %s', http_method.upper(), send_json)
expected_statuses = expected_statuses or HttpStatus.ALL_OK
response = requests.request(http_method, url, json=send_json,
headers={'Content-Type': 'application/vnd.api+json'},
**self._request_kwargs)
if response.status_code not in expected_statuses:
raise DocumentError(f'Could not {http_method.upper()} '
f'({response.status_code}): '
f'{error_from_response(response)}',
errors={'status_code': response.status_code},
response=response,
json_data=send_json)
return response.status_code, response.json() \
if response.content \
else {}, response.headers.get('Location')
评论列表
文章目录