diff --git a/README.rst b/README.rst index cf59484b9dd2a51d482e8177b56814f3e24abe34..a998a6e3d746ad5486b10d25d2995648100f8650 100644 --- a/README.rst +++ b/README.rst @@ -201,7 +201,7 @@ Import transcriptions for a page from files in PAGE XML format .. code:: python - cli.send_xml('ImportTranskribusTranscriptions', id='PAGE_ID', body=open('file.xml')) + cli.send_xml('ImportTranskribusTranscriptions', id='PAGE_ID', body=open('file.xml', 'rb')) Download full logs for each Ponos task in a workflow ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/arkindex/client.py b/arkindex/client.py index c93b72a44afe0c01456be1ee68f1b557450934fb..a90e86c4ac7ac278d6402b28475771d763f04536 100644 --- a/arkindex/client.py +++ b/arkindex/client.py @@ -8,6 +8,7 @@ import yaml from arkindex.auth import TokenSessionAuthentication from arkindex.pagination import ResponsePaginator from arkindex.encoders import XMLEncoder +from io import FileIO from time import sleep from urllib.parse import urlsplit, urlunsplit @@ -178,9 +179,13 @@ class ArkindexClient(apistar.Client): :param str operation_id: An OpenAPI operation ID. :param body: The XML body. - :type body: str or bytes + :type body: str, bytes or a file-like object opened in binary mode :param kwargs: Other arguments sent to :meth:`ArkindexClient.custom_request`. """ + + if isinstance(body, FileIO): + assert body.mode == 'rb', 'File-like objects should be opened in binary mode' + return self.custom_request( operation_id, content=body,