You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I maintain python-dotenv, which Flask uses for loading .env and .flaskenv files, and we've received reports from users confused about the default encoding used by our library: theskumar/python-dotenv#300, which brings me here because it also involves Flask.
Currently, python-dotenv uses the system's preferred encoding to load and store .env files. Since Flask uses dotenv.load_dotenv without the encoding parameter, it inherits that behavior. This means that the encoding of a user's .env or .flaskenv depends on their platform, if I understand Flask's code correctly.
Hence my suggestion: What about making Flask use UTF-8 encoding with the encoding="utf-8" argument?
I don't know if the current behavior was deliberately implemented, and you might want to keep it anyway, but I suspect that it wasn't.
I'm considering making UTF-8 the default in python-dotenv as well, but I'd like your opinion on this since Flask has so many users and relies on python-dotenv's current behavior with respect to encoding.
Here's what it would likely imply for us, and probably also for Flask if it also chooses to use UTF-8:
Pro: It would facilitate sharing .env files between projects since the default encoding would be independent of the platform. Those files aren't really meant to be committed in a repository but it's quite typical for developers to have a sample .env in their repository.
Pro: It would make .env files use the same encoding, by default, as those of Python source files.
Con: It would be a breaking change, but only for users with a non-UTF-8 system encoding and non-UTF-8 strings in their .env files.
Con: It would diverge from Python's handling of the encoding parameter in functions like open.
Does that make sense? I've only started thinking about this and I'm not an expert with regards to Python's handling of encodings so I may well have missed an important point.
The text was updated successfully, but these errors were encountered:
Thank you for reporting this issue back to Flask. I would agree to set the default encoding to UTF-8 in Flask (and python-dotenv), just made a PR for it.
I don't know if the current behavior was deliberately implemented, and you might want to keep it anyway, but I suspect that it wasn't.
python-dotenv doesn't add the encoding argument yet when the flask.cli.load_dotenv function was written...
I maintain python-dotenv, which Flask uses for loading .env and .flaskenv files, and we've received reports from users confused about the default encoding used by our library: theskumar/python-dotenv#300, which brings me here because it also involves Flask.
Currently, python-dotenv uses the system's preferred encoding to load and store .env files. Since Flask uses
dotenv.load_dotenv
without theencoding
parameter, it inherits that behavior. This means that the encoding of a user's.env
or.flaskenv
depends on their platform, if I understand Flask's code correctly.Hence my suggestion: What about making Flask use UTF-8 encoding with the
encoding="utf-8"
argument?I don't know if the current behavior was deliberately implemented, and you might want to keep it anyway, but I suspect that it wasn't.
I'm considering making UTF-8 the default in python-dotenv as well, but I'd like your opinion on this since Flask has so many users and relies on python-dotenv's current behavior with respect to encoding.
Here's what it would likely imply for us, and probably also for Flask if it also chooses to use UTF-8:
encoding
parameter in functions likeopen
.Does that make sense? I've only started thinking about this and I'm not an expert with regards to Python's handling of encodings so I may well have missed an important point.
The text was updated successfully, but these errors were encountered: