slowapi icon indicating copy to clipboard operation
slowapi copied to clipboard

There is 'cp949' encoding error in Windows

Open Junanjunan opened this issue 1 year ago • 0 comments

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.

Junanjunan avatar Jul 11 '24 01:07 Junanjunan