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

There is 'cp949' encoding error in Windows #208

Open
Junanjunan opened this issue Jul 11, 2024 · 0 comments
Open

There is 'cp949' encoding error in Windows #208

Junanjunan opened this issue Jul 11, 2024 · 0 comments

Comments

@Junanjunan
Copy link

Describe the bug
There is encoding error about 'cp949'

File "/home/taltal/git/gnu6/venv/lib/python3.10/site-packages/slowapi/extension.py", line 159, in __init__
    self.app_config = Config(
  File "/home/taltal/git/gnu6/venv/lib/python3.10/site-packages/starlette/config.py", line 66, in __init__
    self.file_values = self._read_file(env_file)
  File "/home/taltal/git/gnu6/venv/lib/python3.10/site-packages/starlette/config.py", line 121, in _read_file
    for line in input_file.readlines():
UnicodeDecodeError: 'cp949' codec can't decode byte 0xec in position 3: illegal multibyte sequence

When I modify the encoding like this, it is enable to handle error

venv/lib/python3.10/site-packages/starlette/config.py/class Config
class Config
...
    def _read_file(self, file_name: str | Path) -> dict[str, str]:
        file_values: typing.Dict[str, str] = {}
        with open(file_name, encoding='utf-8') as input_file:  # There was no "encoding='utf-8'"
            for line in input_file.readlines():
                line = line.strip()
                if "=" in line and not line.startswith("#"):
                    key, value = line.split("=", 1)
                    key = key.strip()
                    value = value.strip().strip("\"'")
                    file_values[key] = value
        return file_values

To Reproduce
Show us your code, only copy the relevant parts, the shorter it is, the easier it is to help you.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Your app (please complete the following information):

  • fastapi or starlette?
  • Version?
  • slowapi version (have you tried with the latest version)?
    Using FastAPI, and starlette also, but the source code is related with starlette
    FastAPI version: 0.109.2
    starlette version: 0.36.3
    slowapi version: 0.1.9

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant