-
Notifications
You must be signed in to change notification settings - Fork 526
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
yaml.load does not support encodings different from current system encoding, cannot you add it? #123
Comments
The yaml.load() method takes an open file object. You must set the encoding when you open the file. This does not have anything to do with PyYAML. Your code contains config_obj = yaml.load(open(config, 'r')) I would suggest to change this to with open(config, 'rt', encoding='utf8') as yml:
config_obj = yaml.load(yml) PS: I did not test this code, but it (or something close to it) should work on Python3. If you are still on python2 you can I suggest to close this issue |
rt mode are not needed explicitly as they are the default options. |
@Felix-neko if your question is not answered by @TormodLandet then please reopen. |
In case anyone finds this thread, thinking PyYaml is the problem: Run python with the It's just Windows being poopy, in my case, as I even used |
Incase of having
Any suggestion!? |
Thanks. Solved my problem of accents returning weird characters :-) |
This is not the correct answer, however.
|
The correct answer is that the YAML specification itself does not support encodings like CP-1252 or CP-1251, rather than this being an issue with PyYAML. What PyYAML could do is implement a custom check for invalid string delimiters like curly quotes, which are valid UTF-8 characters but not valid YAML string delimiters. This issue, highlighted in #800, can result in exceptions like UnicodeDecodeError when the YAML file is not opened with UTF-8 encoding on Windows. However, in certain contexts, the exception might be preferred over incorrect YAML content, which could include these erroneous curly quotes. |
Hi folks!
We try to use PyYaml in Windows with UTF-8 yaml files. Alas,
yaml.load
raises an error: it does not support encoding different from system one (in Windows it is CP-1251). Can you add such a feature to manually set the encoding in which the yaml file is?The traceback, if needed:
The text was updated successfully, but these errors were encountered: