thriftpy2 icon indicating copy to clipboard operation
thriftpy2 copied to clipboard

When environment locale not set, thrift parser would throw UnicodeDecodeError due to using "open" directly.

Open truebit opened this issue 4 years ago • 0 comments

File "/Users/someone/Documents/code/pycharm/test/venv/lib/oython3.6/site-packages/thriftpy2/parser/ init py", line 33, in load
include_dir=include_dir)
File "/Users/someone/Documents/code/oycharm/test/venv/lib/oython3.6/site-packaaes/thriftoy2/oarser/oarser.py", line 577, in parse data = fh.read ()
File "/Users/someone/.pyenv/versions/3.6.0/lib/python3.6/encodinqs/ascii.py'", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte @xe6 in position 113: ordinal not in range(128)

prboblematic code in parser.py:

    url_scheme = urlparse(path).scheme
    if url_scheme == 'file':
        with open(urlparse(path).netloc + urlparse(path).path) as fh:
            data = fh.read()
    elif len(url_scheme) <= 1:
        with open(path) as fh:
            data = fh.read()
    elif url_scheme in ('http', 'https'):
        data = urlopen(path).read()
    else:
        raise ThriftParserError('thriftpy2 does not support generating module '
                                'with path in protocol \'{}\''.format(
                                    url_scheme))

Possible solution: check if python2 or python3, py3 supports open(encoding=xxx), py2 could use io.open

truebit avatar May 13 '21 09:05 truebit