Skip to content
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

'charmap' codec can't decode byte #37

Closed
matej2 opened this issue Nov 13, 2021 · 4 comments
Closed

'charmap' codec can't decode byte #37

matej2 opened this issue Nov 13, 2021 · 4 comments

Comments

@matej2
Copy link
Contributor

matej2 commented Nov 13, 2021

Describe the bug

I tried one of the examples: require-all (https://github.com/openschemas/schemaorg/tree/master/examples/require-all). When I run the example, it returns me the following error:

Specification base set to https://www.schema.org
Using Version 12.0
Traceback (most recent call last):
  File "<user_dir><project_dir>\schemaorg-model-generator\main.py", line 6, in <module>
    schema = Schema('SportsEvent')
  File "<user_dir>.virtualenvs\schemaorg-model-generator-poHh6h-y\lib\site-packages\schemaorg\main\__init__.py", line 35, in __init__
    self.load_type(schema_type)
  File "<user_dir>.virtualenvs\schemaorg-model-generator-poHh6h-y\lib\site-packages\schemaorg\main\__init__.py", line 174, in load_type
    self._load_type(schema_type)
  File "<user_dir>.virtualenvs\schemaorg-model-generator-poHh6h-y\lib\site-packages\schemaorg\main\__init__.py", line 277, in _load_type
    typs = read_types_csv(version = self.version)
  File "<user_dir>.virtualenvs\schemaorg-model-generator-poHh6h-y\lib\site-packages\schemaorg\data\__init__.py", line 91, in read_types_csv
    return read_csv(filename, keyfield=keyfield)
  File "<user_dir>.virtualenvs\schemaorg-model-generator-poHh6h-y\lib\site-packages\schemaorg\utils.py", line 289, in read_csv
    for row in csv_reader:
  File "c:\program files\python39\lib\csv.py", line 111, in __next__
    row = next(self.reader)
  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 0x9d in position 6377: character maps to <undefined>

To Reproduce

  1. Create empty recipe yml as described
  2. Code:
from schemaorg.main import Schema
from schemaorg.utils import read_yaml, write_yaml


recipe = read_yaml('empty.yml')
schema = Schema('SportsEvent')

Expected behavior
I would get schema back.

Version of Python schemaorg
0.1.0

Anything else?
I hope this helps. I hope I provided enough info, ask if you need anything.

@vsoch
Copy link
Member

vsoch commented Nov 13, 2021

It looks like you are on Windows and there is an encoding that isn't recognized. Could you please try seeing if you can tweak this function:

with open(filename, mode='r') as csv_file:
to catch the exception, and then try reading with another codec? There is an example of how to do that here: https://stackoverflow.com/questions/30598350/unicodedecodeerror-charmap-codec-cant-decode-byte-0x8d-in-position-7240-cha

@matej2
Copy link
Contributor Author

matej2 commented Nov 14, 2021

Ok, I tried it and managed to get rid of the error. I will open a PR for this.

@matej2
Copy link
Contributor Author

matej2 commented Nov 15, 2021

The issue is fixed now. Thanks

@matej2 matej2 closed this as completed Nov 15, 2021
@vsoch
Copy link
Member

vsoch commented Nov 15, 2021

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

Successfully merging a pull request may close this issue.

2 participants