qhana_plugin_runner.requests module
Functions for opening files from external URLs.
- qhana_plugin_runner.requests.open_url(url: str, raise_on_error_status=True, **kwargs) Response
Open an url with request.
(see
request()for parameters)It is best to use this function in a
with-statement to get autoclosing behaviour for the returned response. The returned response acts as a context manager.For streaming access set
stream=True.An appropriate exception is raised for an error status. To ignore an error status set
raise_on_error_status=False.
- qhana_plugin_runner.requests.open_url_as_file_like(url: str, raise_on_error_status=True, stream=True, **kwargs) Iterator[Tuple[str, BytesIO, str | None]]
Open an url with requests to be used as a ile like object.
This method should be used as a context manager, i.e., inside a with block, and returns a tuple (filename, file_like, content_type).
This method uses
open_url().The
file_like``object may be a ``urllib3.response.HTTPResponseobject or another object with areadmethod depending on the used url adapter.Example:
>>> with open_url_as_file_like(url) as (filename, file_like, _content_type): >>> print(filename, file_like.read(128))
- qhana_plugin_runner.requests.open_url_as_file_like_simple(url: str, raise_on_error_status=True, stream=True, **kwargs) Iterator[BinaryIO]
Open an url with requests to be used as a ile like object.
This method should be used as a context manager, i.e., inside a with block, and returns a file_like object.
This method uses
open_url().The
file_like``object may be a ``urllib3.response.HTTPResponseobject or another object with areadmethod depending on the used url adapter.Example:
>>> with open_url_as_file_like_simple(url) as file_like: >>> print(file_like.read(128))
- qhana_plugin_runner.requests.retrieve_attribute_metadata_url(url_or_response: str | Response) str | None
Return the attribute metadata URL from the response headers if available.