I am trying to save a python-docx document in Ubuntu, but I get this error: 'ascii' codec can't encode character '\xed' in position 65: ordinal not in range(128)
. I tried to apply this solution, but I get this other error: AttributeError: 'bytes' object has no attribute 'write'
.
This is the code that raised the first error:
current_directory = settings.MEDIA_DIR
file_name = "Rooming {} {}-{}.docx".format(hotel, start_date, end_date)
document.save(current_directory + file_name)
This is the code that raised the latest error:
current_directory = settings.MEDIA_DIR
file_name = "Rooming {} {}-{}.docx".format(hotel, start_date, end_date)
document.save((current_directory + file_name).encode('utf-8'))
I know the file name will end having non standard ascii characters, but I would like to be able to save the files using all those characters.