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

UnicodeDecodeError exception occurs when .env file contains Non-ASCII characters on Windows #175

Closed
greyli opened this issue Apr 22, 2019 · 1 comment

Comments

@greyli
Copy link
Contributor

@greyli greyli commented Apr 22, 2019

When .env file contains Non-ASCII characters, for example:

foo=bar
# 测试

or

foo=测试

It will cause UnicodeDecodeError: 'gbk' codec can't decode bytes in position 25-26: illegal multibyte sequence.

Tested on macOS and Windows, this problem only happened on Windows (both Python 2.7 and Python 3.6).

Here is the full error traceback:

Traceback (most recent call last):
  File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\flask.exe\__main__.py", line 9, in <module>
  File "c:\python27\lib\site-packages\flask\cli.py", line 894, in main
    cli.main(args=args, prog_name=name)
  File "c:\python27\lib\site-packages\flask\cli.py", line 548, in main
    load_dotenv()
  File "c:\python27\lib\site-packages\flask\cli.py", line 608, in load_dotenv
    dotenv.load_dotenv(path)
  File "c:\python27\lib\site-packages\dotenv\main.py", line 309, in load_dotenv
    return DotEnv(f, verbose=verbose).set_as_environment_variables(override=override)
  File "c:\python27\lib\site-packages\dotenv\main.py", line 129, in set_as_environment_variables
    for k, v in self.dict().items():
  File "c:\python27\lib\site-packages\dotenv\main.py", line 115, in dict
    values = OrderedDict(self.parse())
  File "c:\python27\lib\collections.py", line 69, in __init__
    self.__update(*args, **kwds)
  File "c:\python27\lib\_abcoll.py", line 571, in update
    for key, value in other:
  File "c:\python27\lib\site-packages\dotenv\main.py", line 121, in parse
    for mapping in parse_stream(stream):
  File "c:\python27\lib\site-packages\dotenv\main.py", line 83, in parse_stream
    string = stream.read()
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 25-26: illegal multibyte sequence
@greyli greyli changed the title UnicodeDecodeError: 'gbk' codec can't decode bytes in position 25-26: illegal multibyte sequence occurs when comment contains Non-ASCII characters on Windows UnicodeDecodeError exception occurs when comment contains Non-ASCII characters on Windows Apr 22, 2019
@greyli greyli changed the title UnicodeDecodeError exception occurs when comment contains Non-ASCII characters on Windows UnicodeDecodeError exception occurs when .env file contains Non-ASCII characters on Windows Apr 22, 2019
@greyli

This comment has been minimized.

Copy link
Contributor Author

@greyli greyli commented Apr 22, 2019

This issue will be fixed with #161, closing it now.

@greyli greyli closed this Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.