thriftpy
thriftpy copied to clipboard
Parser doesn't support absolute path on windows
Using urlparse to get the path's schema ,but on windows ,it doesn't work well. When loads file using absolute path , it would raise
raise ThriftParserError('ThriftPy does not support generating module ' 'with path in protocol '{}''.format( url_scheme))
Could it be wrotten like
if url_scheme in ('http', 'https'):
data = urlopen(path).read()
else:
try:
with open(path) as fh:
data = fh.read()
except Exception as e:
raise ThriftParserError('ThriftPy does not support generating module '
'with path in protocol \'{}\''.format(
url_scheme),e)
Can you be more specific about the parameter on how to reproduce and why this code fixed the bug?
test_thrift= thriftpy.load(r'C:\test.thrift',module_name='test_thrift')
urlparse with return
ParseResult(scheme='e', netloc='', path='\test.thrift', params='', query='', fragment='')
# parser.py line 487
url_scheme = urlparse(path).scheme
if url_scheme == '':
with open(path) as fh:
data = fh.read()
elif url_scheme in ('http', 'https'):
data = urlopen(path).read()
else:
raise ThriftParserError('ThriftPy does not support generating module '
'with path in protocol \'{}\''.format(
url_scheme))
because the url_scheme is e, it goes into the else branch and raise ThriftParserError
I see, I'll look into this problem later.
For now, you may want to check parser_fp
function, located at https://github.com/eleme/thriftpy/blob/develop/thriftpy/parser/parser.py#L518
I am also encountering this issue. My temporary fix was to edit thriftpy/parser/parser.py, and change line 488 from
if url_scheme == '':
to
if url_scheme in ('c', ''):
This will fix it for files located in the C: drive as this resolves to a uri protocol of c, we probably need to also add 'd', 'e', 'f' etc to be safe - or do something a bit more sensible.
The problem only occurs when I use pip to install thriftpy. No such problem when I use conda to install.
Tested on: Windows 7 Anaconda Python 3.5 thriftpy 0.3.8 (installed via conda)
I confirm the suggested patch "https://github.com/eleme/thriftpy/issues/234#issuecomment-249794576" is mandatory to have a working Thriftpy on WinPython.
I suspect the bug was not in 0.3.8, only in 0.3.9
Theoretically, you try to open the path as a file as the fallback to unsupported schemes, rather than simply giving up. Let the filesystem figure out what it can and can't open rather than trying to preempt it.
Alternatively, maybe it's a bad idea for "load" to magically coerce different path types to begin with, and the function should have separate treatments for "filesystem paths" and "URLs".
What is the plan to fix this issue? Why wasn't the PR accepted?
As it stands Windows users cannot use packages that use thirftpy, e.g. happybase, because they import thriftpy and it falls over..
Any update on the status of this issue?
Guys, I'm also hitting this issue when trying to use py_zipkin on windows.
@wooparadog stays pretty busy, from what it sounds like. I agree that #285 is a good enough approach, we should accept it.
Hi all, I accept https://github.com/markmnl/thriftpy/commit/0801f462c044e2def9a305b38f77fb89ead2c6cb in thriftpy2 to fix it, thanks!