yaml.load does not support encodings different from current system encoding, cannot you add it?
See original GitHub issueHi 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:
Traceback (most recent call last):
File "D:/Projects/bricks2/main.py", line 45, in <module>
main_wnd.load_components()
File "D:\Projects\bricks2\bricks\gui\main_wnd.py", line 286, in load_components
self.registry.load()
File "D:\Projects\bricks_cli\bricks_cli\registry.py", line 38, in load
self._load_config(root_node, config)
File "D:\Projects\bricks_cli\bricks_cli\registry.py", line 44, in _load_config
config_obj = yaml.load(open(config, 'r'))
File "C:\Python35\lib\site-packages\yaml\__init__.py", line 73, in load
loader = Loader(stream)
File "C:\Python35\lib\site-packages\yaml\loader.py", line 24, in __init__
Reader.__init__(self, stream)
File "C:\Python35\lib\site-packages\yaml\reader.py", line 85, in __init__
self.determine_encoding()
File "C:\Python35\lib\site-packages\yaml\reader.py", line 124, in determine_encoding
self.update_raw()
File "C:\Python35\lib\site-packages\yaml\reader.py", line 178, in update_raw
data = self.stream.read(size)
File "C:\Python35\lib\encodings\cp1251.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 2574: character maps to <undefined>
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to set the character encoding in a yaml file - Stack Overflow
A YAML processor must support the UTF-16 and UTF-8 character encodings. If a character stream does not begin with a byte order mark...
Read more >YAML: The Missing Battery in Python
Note: The documentation for Python's logging framework mentions YAML despite the fact that the language doesn't support YAML natively.
Read more >PyYAML Documentation
yaml.load detects the encoding by checking the BOM (byte order mark) sequence at the beginning of the string/file. If no BOM is present, ......
Read more >Core Features - Spring
Here you can learn about the key features that you may want to use and ... If the file has an encoding other...
Read more >Configuration - Sphinx documentation
Note that the current builder tag is not available in conf.py , as it is created after the ... You can add a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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
I would suggest to change this to
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
import codecs
and usecodecs.open
.I suggest to close this issue
Incase of having
!!python/tuple
in the yaml file, I can’t apply utf-8 encoding anymore.Any suggestion!?