[Django]-Django ContentFile() unexpected empty line (django.core.files.base)

3👍

I solved it by changing the last line of the save_entry function to

default_storage.save(filename, ContentFile(content.encode('ascii')))

per this answer https://stackoverflow.com/a/4053205

👤Pelux

0👍

I’ve got the same issue and here is my solution:

ContentFile uses StringIO if you provide content as a string or BytesIO if you provide content as ByteArray. I guessed it could be issue of StringIO class so I simply converted my content to byte array and passed fixed argument so ContentFile class initialized BytesIO as stream_class:

byte_list = []
a_byte_array =  bytearray(content,"utf-8")
    for byte in a_byte_array:
    binary = bin(byte)
    byte_list.append(binary)
save(query, a_byte_array)

Leave a comment