Repository: streamlit/streamlit

Issue:
Suggestion: Specify the character set as utf-8 when opening the file in the file config.py, or use character set detection
### Summary

Suggestion: Specify the character set as utf-8 when opening the file in the file config.py, or use character set detection. 

### Steps to reproduce
1. utf-8 char in config.toml: 

```toml
[runner]
# 禁止掉 magic commands
magicEnabled = false
```

2. streamlit run xxx.py

3. get error

```shell
  File "c:\python38_64\lib\site-packages\streamlit\hashing.py", line 40, in <module>
    from streamlit.folder_black_list import FolderBlackList
  File "c:\python38_64\lib\site-packages\streamlit\folder_black_list.py", line 39, in <module>
    if config.get_option("global.developmentMode"):
  File "c:\python38_64\lib\site-packages\streamlit\config.py", line 104, in get_option
    config_options = get_config_options()
  File "c:\python38_64\lib\site-packages\streamlit\config.py", line 1055, in get_config_options
    file_contents = input.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 6: illegal multibyte sequence
```
 
caused by config.py ,code snippet:

```py
         with open(filename, "r") as input:
                file_contents = input.read()
```

Treatment method:

```py
with open(filename, "r",encoding='utf-8') as input:
                file_contents = input.read()
```



Discussion:
This reminds me of #2615. Might be worth us auditing `git grep open\(` across the board for this kind of issue.
Good code practice, just like Golang source file must be encoded in UTF-8.
I did a little more research and found some interesting things:

* [PEP 597](https://discuss.python.org/t/pep-597-use-utf-8-for-default-text-file-encoding/1819) - proposal for defaulting to UTF-8
* From the proposal, I ran across [how AWS is handling this](https://github.com/aws/aws-cli/issues/5996) with their CLI library is handling things.
* Another [relevant discussion ](https://github.com/aws/aws-cli/issues/4134) where some env vars re suggested, such as `PYTHONUTF8`
Thanks for the report @yinhedot ! I think @jroes is right! We should just default to UTF-8.

Resolving patch:
diff --git a/lib/streamlit/config.py b/lib/streamlit/config.py
--- a/lib/streamlit/config.py
+++ b/lib/streamlit/config.py
@@ -1078,7 +1078,7 @@ def get_config_options(
             if not os.path.exists(filename):
                 continue
 
-            with open(filename, "r") as input:
+            with open(filename, "r", encoding="utf-8") as input:
                 file_contents = input.read()
 
             _update_config_with_toml(file_contents, filename)
diff --git a/lib/streamlit/secrets.py b/lib/streamlit/secrets.py
--- a/lib/streamlit/secrets.py
+++ b/lib/streamlit/secrets.py
@@ -86,7 +86,7 @@ def _parse(self, print_exceptions: bool) -> Mapping[str, Any]:
                 return self._secrets
 
             try:
-                with open(self._file_path) as f:
+                with open(self._file_path, encoding="utf-8") as f:
                     secrets_file_str = f.read()
             except FileNotFoundError:
                 if print_exceptions:
diff --git a/lib/streamlit/source_util.py b/lib/streamlit/source_util.py
--- a/lib/streamlit/source_util.py
+++ b/lib/streamlit/source_util.py
@@ -28,4 +28,4 @@ def open_python_file(filename):
         # found, opens as utf-8.
         return tokenize.open(filename)
     else:
-        return open(filename, "r")
+        return open(filename, "r", encoding="utf-8")


Test patch: