def request(self, **kwargs) -> Model:
"""
Make a HTTP request of of type method.
You should generally leave this method alone. If you need to customise the behaviour use the methods that
this method uses.
"""
kwargs = self.get_request_kwargs(request_model=self.request_model, **kwargs)
# get_request_kwargs can permanently alter the url, method and session
self.url = kwargs.pop('url', self.url)
self.method = kwargs.pop('method', self.method)
self.session = kwargs.pop('session', self.session)
try:
response = getattr(self.session, self.method)(self.url, **kwargs)
return self.create_response_model(response, self.request_model)
except requests.Timeout:
raise EaterTimeoutError("%s.%s for URL '%s' timed out." % (
type(self).__name__,
self.method,
self.url
))
except requests.RequestException as exc_info:
raise EaterConnectError("Exception raised for URL '%s'." % self.url) from exc_info
评论列表
文章目录