| :py:mod:`airflow.providers.http.hooks.http` |
| =========================================== |
| |
| .. py:module:: airflow.providers.http.hooks.http |
| |
| |
| Module Contents |
| --------------- |
| |
| Classes |
| ~~~~~~~ |
| |
| .. autoapisummary:: |
| |
| airflow.providers.http.hooks.http.HttpHook |
| |
| |
| |
| |
| .. py:class:: HttpHook(method = 'POST', http_conn_id = default_conn_name, auth_type = HTTPBasicAuth) |
| |
| Bases: :py:obj:`airflow.hooks.base.BaseHook` |
| |
| Interact with HTTP servers. |
| |
| :param method: the API method to be called |
| :param http_conn_id: :ref:`http connection<howto/connection:http>` that has the base |
| API url i.e https://www.google.com/ and optional authentication credentials. Default |
| headers can also be specified in the Extra field in json format. |
| :param auth_type: The auth type for the service |
| |
| .. py:attribute:: conn_name_attr |
| :annotation: = http_conn_id |
| |
| |
| |
| .. py:attribute:: default_conn_name |
| :annotation: = http_default |
| |
| |
| |
| .. py:attribute:: conn_type |
| :annotation: = http |
| |
| |
| |
| .. py:attribute:: hook_name |
| :annotation: = HTTP |
| |
| |
| |
| .. py:method:: get_conn(self, headers = None) |
| |
| Returns http session for use with requests |
| |
| :param headers: additional headers to be passed through as a dictionary |
| |
| |
| .. py:method:: run(self, endpoint = None, data = None, headers = None, extra_options = None, **request_kwargs) |
| |
| Performs the request |
| |
| :param endpoint: the endpoint to be called i.e. resource/v1/query? |
| :param data: payload to be uploaded or request parameters |
| :param headers: additional headers to be passed through as a dictionary |
| :param extra_options: additional options to be used when executing the request |
| i.e. {'check_response': False} to avoid checking raising exceptions on non |
| 2XX or 3XX status codes |
| :param request_kwargs: Additional kwargs to pass when creating a request. |
| For example, ``run(json=obj)`` is passed as ``requests.Request(json=obj)`` |
| |
| |
| .. py:method:: check_response(self, response) |
| |
| Checks the status code and raise an AirflowException exception on non 2XX or 3XX |
| status codes |
| |
| :param response: A requests response object |
| |
| |
| .. py:method:: run_and_check(self, session, prepped_request, extra_options) |
| |
| Grabs extra options like timeout and actually runs the request, |
| checking for the result |
| |
| :param session: the session to be used to execute the request |
| :param prepped_request: the prepared request generated in run() |
| :param extra_options: additional options to be used when executing the request |
| i.e. ``{'check_response': False}`` to avoid checking raising exceptions on non 2XX |
| or 3XX status codes |
| |
| |
| .. py:method:: run_with_advanced_retry(self, _retry_args, *args, **kwargs) |
| |
| Runs Hook.run() with a Tenacity decorator attached to it. This is useful for |
| connectors which might be disturbed by intermittent issues and should not |
| instantly fail. |
| |
| :param _retry_args: Arguments which define the retry behaviour. |
| See Tenacity documentation at https://github.com/jd/tenacity |
| |
| |
| .. code-block:: python |
| |
| hook = HttpHook(http_conn_id="my_conn", method="GET") |
| retry_args = dict( |
| wait=tenacity.wait_exponential(), |
| stop=tenacity.stop_after_attempt(10), |
| retry=requests.exceptions.ConnectionError, |
| ) |
| hook.run_with_advanced_retry(endpoint="v1/test", _retry_args=retry_args) |
| |
| |
| |
| .. py:method:: url_from_endpoint(self, endpoint) |
| |
| Combine base url with endpoint |
| |
| |
| .. py:method:: test_connection(self) |
| |
| Test HTTP Connection |
| |
| |
| |