Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django default_storage breaks on non-ascii characters in files #11337

Closed
whatisgalen opened this issue Aug 15, 2024 · 4 comments · Fixed by #11372
Closed

Django default_storage breaks on non-ascii characters in files #11337

whatisgalen opened this issue Aug 15, 2024 · 4 comments · Fixed by #11372
Labels
bug Type: Bug Something isn't working

Comments

@whatisgalen
Copy link
Member

When importing a csv, often Django's default_storage module is used to handle the file, like so:

with default_storage.open(csv_file_path, mode="r") as csvfile:
            reader = csv.reader(csvfile)
            data = {"csv": [line for line in reader], "csv_file": csv_file_name}

However the default encoding used is ascii, creating an error for non-ascii characters. Django's default_stoarge.open method does not take an encoding= kwarg like the python open method does, so there is no good way to force utf-8 encoding when opening files this way.

@jacobtylerwalls
Copy link
Member

@whatisgalen you might consider posting on the django forum to gauge appetite for doing the same thing for the storage interface that was done for the file interface in 5.0 to allow all kwargs through to open() (assuming still a problem in 5.1)

@whatisgalen
Copy link
Member Author

@whatisgalen you might consider posting on the django forum to gauge appetite for doing the same thing for the storage interface that was done for the file interface in 5.0 to allow all kwargs through to open() (assuming still a problem in 5.1)

Just posted!

@jacobtylerwalls
Copy link
Member

However the default encoding used is ascii

Just noting that this platform dependent. Were you testing with Windows?

@whatisgalen
Copy link
Member Author

Just noting that this platform dependent. Were you testing with Windows?

Ubuntu 20 actually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants