qhana_plugin_runner.requests module

Functions for opening files from external URLs.

qhana_plugin_runner.requests.get_mimetype(response: Response, default=None) str | None
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.HTTPResponse object or another object with a read method 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.HTTPResponse object or another object with a read method 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.

Parameters:

url_or_response (str | Response) – a url or a response instance

Raises:

TypeError – if the input url or response type is not supported

Returns:

the url to related attribute metadata

Return type:

str|None

qhana_plugin_runner.requests.retrieve_data_type(url_or_response: str | Response) str | None

Return the data type from the response headers if available.

Parameters:

url_or_response (str | Response) – a url or a response instance

Raises:

TypeError – if the input url or response type is not supported

Returns:

the data type

Return type:

str|None

qhana_plugin_runner.requests.retrieve_filename(url_or_response: str | Response) str

Given an url to a file or an url response, it returns the name of the file :param url_or_response: str | Response :return: str