In issue #171, it was reported that replacing data files was not working due to an incorrect mime-type being submitted. Specifically, when trying to replace a docx file, the pyDataverse library was supplying text/plain as the mime-type, which was causing the issue.
It appears that this error originated from Python's request library, which was failing to supply the correct mime-type upon upload and was falling back to text/plain. As a result, Dataverse rejected the replacement due to a different mime type being supplied than what already existed.
In order to resolve the issue, the proposed solution involves extending the post_request and determining the mime-types before initiating a POST request. For this purpose, the implementation employs Python's mimetypes library to predict the mimetype. Subsequently, the identified mime-type is passed to the request.post method. If the mime-type cannot be guessed, the method returns to the current implementation.
Overview
In issue #171, it was reported that replacing data files was not working due to an incorrect mime-type being submitted. Specifically, when trying to replace a
docx
file, thepyDataverse
library was supplyingtext/plain
as the mime-type, which was causing the issue.It appears that this error originated from Python's
request
library, which was failing to supply the correct mime-type upon upload and was falling back totext/plain.
As a result, Dataverse rejected the replacement due to a different mime type being supplied than what already existed.In order to resolve the issue, the proposed solution involves extending the
post_request
and determining the mime-types before initiating a POST request. For this purpose, the implementation employs Python'smimetypes
library to predict the mimetype. Subsequently, the identified mime-type is passed to therequest.post
method. If the mime-type cannot be guessed, the method returns to the current implementation.ToDos
Closes
Fixes #171