Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ced19d4

Browse files
authored
Open UA_PARSER_YAML as binary
The yaml files should be parsed as UTF8. In text mode, `open` uses `locale.getpreferredencoding`, which unless Python is run in UTF-8 mode (see PEP 540) might be complete nonsense (it's the encoding in `LC_CTYPE` on POSIX systems, and almost certainly a garbage ANSI codepage on windows, likely cp1252 for western windows systems). Open the file in binary mode and pass the binary stream to pyyaml for it to decode to avoid this error. Closes #98
1 parent 4b1a066 commit ced19d4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ua_parser/user_agent_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def GetFilters(
477477
except ImportError:
478478
from yaml import SafeLoader
479479

480-
with open(UA_PARSER_YAML) as fp:
480+
with open(UA_PARSER_YAML, 'rb') as fp:
481481
regexes = yaml.load(fp, Loader=SafeLoader)
482482

483483
USER_AGENT_PARSERS = []

0 commit comments

Comments
 (0)