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

Skip to content

Using newest regexes.yaml yields an error when loading module #98

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

Closed
markdepalma opened this issue Dec 9, 2021 · 0 comments
Closed

Comments

@markdepalma
Copy link
Contributor

This is being done on a Windows machine in a PowerShell session. See repro and error below:

$env:UA_PARSER_YAML = "C:\\Temp\\regexes.yaml"
>>> from ua_parser import user_agent_parser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\mark.depalma\Desktop\Projects\Intune\Scripts\DynamicRedirector\uatestenv\lib\site-packages\ua_parser\user_agent_parser.py", line 481, in <module>
    regexes = yaml.load(fp, Loader=SafeLoader)
  File "C:\Users\mark.depalma\Desktop\Projects\Intune\Scripts\DynamicRedirector\uatestenv\lib\site-packages\yaml\__init__.py", line 81, in load
    return loader.get_single_data()
  File "C:\Users\mark.depalma\Desktop\Projects\Intune\Scripts\DynamicRedirector\uatestenv\lib\site-packages\yaml\constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "yaml\_yaml.pyx", line 673, in yaml._yaml.CParser.get_single_node
  File "yaml\_yaml.pyx", line 687, in yaml._yaml.CParser._compose_document
  File "yaml\_yaml.pyx", line 731, in yaml._yaml.CParser._compose_node
  File "yaml\_yaml.pyx", line 845, in yaml._yaml.CParser._compose_mapping_node
  File "yaml\_yaml.pyx", line 729, in yaml._yaml.CParser._compose_node
  File "yaml\_yaml.pyx", line 806, in yaml._yaml.CParser._compose_sequence_node
  File "yaml\_yaml.pyx", line 731, in yaml._yaml.CParser._compose_node
  File "yaml\_yaml.pyx", line 845, in yaml._yaml.CParser._compose_mapping_node
  File "yaml\_yaml.pyx", line 694, in yaml._yaml.CParser._compose_node
  File "yaml\_yaml.pyx", line 858, in yaml._yaml.CParser._parse_next_event
  File "yaml\_yaml.pyx", line 867, in yaml._yaml.input_handler
  File "C:\Program Files\Python39\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 461: character maps to <undefined>

When manually stepping through code I saw that the file was being opened using 'cp1252' encoding by default. Adjusting the code so that the open handle is created as binary resolves the issue.

Line 480 of user_agent_parser.py with fix:
with open(UA_PARSER_YAML, 'rb') as fp:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant