Repository: yt-dlp/yt-dlp

Issue:
Unable to use Firefox containers in multibyte environments
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a bug unrelated to a specific site
- [X] I've verified that I'm running yt-dlp version **2023.07.06** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)

### Provide a description that is worded well enough to be understood

Under the following conditions:
- --cookies-from-browser 
- Firefox
- containers
- there are any multibyte character in the **name** of any containers

yt-dlp will stop at the position showed below.
This is not limited to the using container, but just any container with even one such character exist will cause the problem.

This issue looks similar to issue #1276 , but happens when reading the firefox containers instead of cookies.
Not passing any container parameter (just 'firefox' instead of 'firefox::sth' ) , or removing all multibyte characters from all container names resolves this issue, but even firefox containers default names will contain such characters.


### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Command-line config: ['--simulate', '-vU', '--cookies-from-browser', 'firefox::ny', 'https://www.youtube.com/watch?v=KMU0tzLwhbE']
[debug] Encodings: locale cp932, fs utf-8, pref cp932, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.07.06 [b532a3481] (win_exe)
[debug] Python 3.8.10 (CPython AMD64 64bit) - Windows-10-10.0.19045-SP0 (OpenSSL 1.1.1k  25 Mar 2021)
[debug] exe versions: ffmpeg 2021-03-16-git-9383885c0d-full_build-www.gyan.dev (setts), ffprobe 2021-03-16-git-9383885c0d-full_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.18.0, brotli-1.0.9, certifi-2023.05.07, mutagen-1.46.0, sqlite3-2.6.0, websockets-11.0.3
[Cookies] Extracting cookies from firefox
[debug] Extracting cookies from: "C:\Users\Neil\AppData\Roaming\Mozilla\Firefox\Profiles\tcd6o0so.default-1660320630895\cookies.sqlite"
Traceback (most recent call last):
  File "yt_dlp\__main__.py", line 17, in <module>
  File "yt_dlp\__init__.py", line 1008, in main
  File "yt_dlp\__init__.py", line 962, in _real_main
  File "yt_dlp\YoutubeDL.py", line 676, in __init__
  File "yt_dlp\YoutubeDL.py", line 3953, in print_debug_header
  File "yt_dlp\YoutubeDL.py", line 3997, in _setup_opener
  File "yt_dlp\cookies.py", line 106, in load_cookies
  File "yt_dlp\cookies.py", line 123, in extract_cookies_from_browser
  File "yt_dlp\cookies.py", line 157, in _extract_firefox_cookies
  File "json\__init__.py", line 293, in load
UnicodeDecodeError: 'cp932' codec can't decode byte 0x94 in position 1408: illegal multibyte sequence
[13440] Failed to execute script '__main__' due to unhandled exception!
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/cookies.py b/yt_dlp/cookies.py
--- a/yt_dlp/cookies.py
+++ b/yt_dlp/cookies.py
@@ -138,7 +138,7 @@ def _extract_firefox_cookies(profile, container, logger):
         containers_path = os.path.join(os.path.dirname(cookie_database_path), 'containers.json')
         if not os.path.isfile(containers_path) or not os.access(containers_path, os.R_OK):
             raise FileNotFoundError(f'could not read containers.json in {search_root}')
-        with open(containers_path) as containers:
+        with open(containers_path, encoding='utf8') as containers:
             identities = json.load(containers).get('identities', [])
         container_id = next((context.get('userContextId') for context in identities if container in (
             context.get('name'),


Test patch: