ethereum / eth-utils

Utility functions for working with ethereum related codebases.
https://eth-utils.readthedocs.io/en/latest/
MIT License
312 stars 148 forks source link

Cannot import eth_utils due to character encoding #257

Closed LeoHLee closed 10 months ago

LeoHLee commented 10 months ago

What happened?

Cannot import eth_utils on a Windows PC where the system language is Chinese.

Code that produced the error

import eth_utils

Full error output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Leo_h\AppData\Local\Programs\Python\Python311\Lib\site-packages\eth_utils\__init__.py", line 86, in <module>
    from .network import (
  File "C:\Users\Leo_h\AppData\Local\Programs\Python\Python311\Lib\site-packages\eth_utils\network.py", line 49, in <module>
    networks = initialize_network_objects()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Leo_h\AppData\Local\Programs\Python\Python311\Lib\site-packages\eth_utils\network.py", line 27, in initialize_network_objects
    network_data = json.load(open_file)
                   ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Leo_h\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
                 ^^^^^^^^^
UnicodeDecodeError: 'gbk' codec can't decode byte 0x88 in position 247555: illegal multibyte sequence

Fill this section in if you know how this could or should be fixed

I found a character '◈' in eth_networks.json, which may have caused this problem. I suggest specifying UTF-8 encoding explicitly when parsing this file.

eth-utils Version

2.3.0

Python Version

3.11.3

Operating System

Windows 10 22H2

Output from pip freeze

base58==2.1.1
bitarray==2.8.2
blinker==1.6.3
click==8.1.7
colorama==0.4.6
cytoolz==0.12.2
eth-abi==4.2.1
eth-account==0.9.0
eth-hash==0.5.2
eth-keyfile==0.6.1
eth-keys==0.4.0
eth-rlp==0.3.0
eth-typing==3.5.1
eth-utils==2.3.0
Flask==3.0.0
hexbytes==0.3.1
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
parsimonious==0.9.0
pycryptodome==3.19.0
regex==2023.10.3
rlp==3.0.0
toolz==0.12.0
typing_extensions==4.8.0
Werkzeug==3.0.0
fselmo commented 10 months ago

duplicated by #258