Closed TomZastrow closed 6 years ago
It could be solved this way:
import io ....
with io.open(bag_info_path, 'w', encoding='utf-8') as f: ...
f.write("%s: %s\n" % (unicode(h), unicode(val))) # two times
Interesting, do you have a test-case against the latest version of bagit which reproduces the failure? I added one to the test-suite but it's not failing and I was wondering whether it was possible that the problem was that your code had unicode data in a regular byte-string.
This changed almost a year ago when #55 was merged and now all of the text I/O uses a simple open_text_file
wrapper for codecs.open
:
https://github.com/LibraryOfCongress/bagit-python/blob/master/bagit.py#L129
The bit of source above still shows _make_tag_file
using with open(bag_info_path, 'w') as f:
rather than open_text_file
:
https://github.com/LibraryOfCongress/bagit-python/blob/master/bagit.py#L1098
Sorry, it was a problem with the encoding of my Python code file ... adding a
Did the trick.
Thanks again.
When adding metadata with special characters, I got an error:
Which seems to be here in this function:
Maybe file can be opened for writing Unicode:
with open(bag_info_path, 'w', encoding=utf-8) as f: