etianen / django-s3-storage

Django Amazon S3 file storage.
BSD 3-Clause "New" or "Revised" License
412 stars 94 forks source link

Cannot open files in plain text mode #160

Closed arveitch closed 10 months ago

arveitch commented 10 months ago

I am working with CSV files which need to be opened in plain text mode. With django-storage I had been using:

with object.file.open('r') as f:
    csv_reader = csv.DictReader(f)

But that gives me an error and I need to open it in binary mode and do this instead:

with object.file.open() as f:
    csv_reader = csv.DictReader(io.StringIO(f.read().decode('utf-8'))

I'm wondering if this is a bug or if this is how my code should change.

(I am loving the product, I like that it seeks(0) and handles encoding properly when I am writing CSV files. It is much closer to the the native Django Storage.)

etianen commented 10 months ago

It's a bug!

And I just fixed it (but only for Python 3.11+) 🙇

Please upgrade to 0.15.0

arveitch commented 10 months ago

Thanks for fixing this so quickly! I'm on Python 3.11 so that's fine.

I think it's a great product, it deserves to be much more widely known about.