We've run into errors after upgrading our XNATpy version when trying to upload .zip or .tar files with more than 1 file in.
We have previously been able to use commands like the examples given below to upload .zip files containing multiple DICOM files:
prearchive_session = session.services.import_("dicom.zip", project=project_string, subject=subject_string, experiment=experiment_string, destination="/prearchive")
However when we use these same commands in XNATpy 0.5.0 we see this error for both:
Traceback (most recent call last):
File "/home/duncan/Desktop/xnat-test/xnat-project.py", line 22, in <module>
prearchive_session = session.services.import_("dicom2.zip", project=project_string, subject=subject_string, experiment=experiment_string, destination="/prearchive")
File "/home/duncan/anaconda3/lib/python3.9/site-packages/xnat/services.py", line 239, in import_
response = self.xnat_session.upload_file(uri=uri, path=path, query=query, content_type=content_type, method='post')
File "/home/duncan/anaconda3/lib/python3.9/site-packages/xnat/session.py", line 769, in upload_file
self.upload_stream(uri=uri, stream=file_handle, **kwargs)
File "/home/duncan/anaconda3/lib/python3.9/site-packages/xnat/session.py", line 899, in upload_stream
response =
self.interface.post(uri, data=stream, headers=headers, timeout=timeout)
File "/home/duncan/anaconda3/lib/python3.9/site-packages/requests/sessions.py", line 635, in post
return self.request("POST", url, data=data, json=json, **kwargs)
File "/home/duncan/anaconda3/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/home/duncan/anaconda3/lib/python3.9/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/home/duncan/anaconda3/lib/python3.9/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/home/duncan/anaconda3/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/home/duncan/anaconda3/lib/python3.9/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/home/duncan/anaconda3/lib/python3.9/site-packages/urllib3/connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/home/duncan/anaconda3/lib/python3.9/http/client.py", line 1285, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/home/duncan/anaconda3/lib/python3.9/http/client.py", line 1331, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/home/duncan/anaconda3/lib/python3.9/http/client.py", line 1280, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/home/duncan/anaconda3/lib/python3.9/http/client.py", line 1069, in _send_output
for chunk in chunks:
File "/home/duncan/anaconda3/lib/python3.9/http/client.py", line 1024, in _read_readable
datablock = readable.read(self.blocksize)
File "/home/duncan/anaconda3/lib/python3.9/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa8 in position 10: invalid start byte
I've tested these two commands with XNATpy 0.4.3 against XNAT 1.8.6.1 and XNAT 1.8.7 and they work, and tested against the same 2 XNAT versions with XNATpy 0.5.0 and they fail (so I don't think this is an XNAT issue directly). We've tried changing the .zip and .tar files compression and other settings but this hasn't seemed to help.
I notice in the release notes for XNATpy 0.5.0 it mentions "Reworked upload functions to have more clear behaviour" so either how these functions are used have changed and we're now using them incorrectly, or errors have been introduced somewhere in the process.