-
Notifications
You must be signed in to change notification settings - Fork 430
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
UnicodeDecodeError exception occurs when .env file contains Non-ASCII characters on Windows #300
Comments
@theskumar Maybe we could just set the default encoding to UTF-8 (I would like to make a PR for this)? |
or just add a function to dect which encode?
From An idea
… 在 2021年1月25日,21:04,Grey Li ***@***.***> 写道:
@theskumar Maybe we could just set the default encoding to UTF-8?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I think it would be best to try and detect encoding with a library that was built around detecting encoding with speed and if that fails, default the encoding to UTF-8. |
Exactly, that is that the guy do in the Similar situation. Set UTF8 as default, and add a function to dect the encode |
This happens to me when I'm using
|
By the way, I turn to Arch Linux. The Chinese comment work fine. Just byebye windows |
Having the same problem on a win10 machine (due to a cyrillic character in a comment). Approach suggested by @BackMountainDevil (using |
Hi everyone and thanks for the feedback. This looks like a bug in Flask (for not using I think that changing the default encoding would be a good idea. It would be a breaking change but the current behavior (defaulting to system's encoding) doesn't make sense to me, so we could probably do it. Furthermore, UTF-8 is the default encoding for Python source code, so using that encoding for .env files by default would certainly be expected. About that change: it would be breaking Flask since Flask uses Detecting the encoding automatically would probably be too brittle (you can't detect all encodings with 100% probability) and bring more surprises to users so I'd rather avoid doing that. Encoding detection can be very useful when you don't know the encoding of documents but I think that you should know the encoding of your project files. |
@bbc2 Thanks a lot for looking into this. Maybe this is a stupid question (it's early morning after all) but wouldn't be enough to change the default encoding of the |
I think I see what you mean. The change wouldn't break the code directly (you would still call functions like It may well affect a very small proportion of users, but we have a lot of them so I'm trying to be careful. Perhaps the main drawback of such a change, except for it being a breaking change, is the fact that it would make python-dotenv diverge from Python's behavior with regards to file encoding: https://docs.python.org/3/library/os.html#file-names-command-line-arguments-and-environment-variables. In Python, |
Similar to Issue #175 UnicodeDecodeError exception occurs when .env file contains Non-ASCII characters on Windows.
And that issue said it sloved in PR 161 30 Apr 2019, but it did happen in the version 0.15.0 which released on 29 Oct 2020.
Similar situation I met before about decode on windows
Info about env
OS like
pip package info
what situation will error
code
see rpo
point
When I add a little Chinese comment in file -
.flaskenv
, it will happen. If delete all Chinese comment, it work fine.bad result
add a comment to the end of
.flaskenv
. Just like thisThen run flask
good reslut
The text was updated successfully, but these errors were encountered: