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

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

Closed
truebit opened this issue May 13, 2021 · 0 comments · Fixed by #173

Comments

@truebit
Copy link
Contributor

truebit commented May 13, 2021

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

@ethe ethe closed this as completed in #173 May 26, 2023
ethe added a commit that referenced this issue May 26, 2023
try to fix issue #172 when system locale not set
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.

1 participant