From eaead2389d06a584e1a06bf730b1f7a7a407037e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6ffner?= Date: Wed, 24 Jul 2024 22:23:45 +0200 Subject: [PATCH] Fix handling of empty metadata Relates to datalad/datalad-dataverse#320 --- pyDataverse/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyDataverse/api.py b/pyDataverse/api.py index 23b0493..e45b18e 100644 --- a/pyDataverse/api.py +++ b/pyDataverse/api.py @@ -1847,9 +1847,10 @@ def upload_datafile(self, identifier, filename, json_str=None, is_pid=True): url += "/datasets/{0}/add".format(identifier) files = {"file": open(filename, "rb")} - return self.post_request( - url, data={"jsonData": json_str}, files=files, auth=True - ) + metadata = {} + if json_str is not None: + metadata["jsonData"] = json_str + return self.post_request(url, data=metadata, files=files, auth=True) def update_datafile_metadata(self, identifier, json_str=None, is_filepid=False): """Update datafile metadata.