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

I don't know what the problem is #5

Closed
zzll0909 opened this issue Feb 26, 2020 · 4 comments
Closed

I don't know what the problem is #5

zzll0909 opened this issue Feb 26, 2020 · 4 comments

Comments

@zzll0909
Copy link

zxing: error: Unknown Java exception: b'Exception in thread "main" java.lang.IllegalArgumentException: URI path component is empty\r\n\tat sun.nio.fs.WindowsUriSupport.fromUri(Unknown Source)\r\n\tat sun.nio.fs.WindowsFileSystemProvider.getPath(Unknown Source)\r\n\tat java.nio.file.Paths.get(Unknown Source)\r\n\tat com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)\r\n\tat com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)\r\n'

@zzll0909
Copy link
Author

image

@dlenski
Copy link
Owner

dlenski commented Feb 26, 2020

Hmmm… I don't know either. The zxing Java binary is notably terrible at parsing the filenames sent to it by Python (it's possible that the Chinese characters in the path are confusing it). The fact that you're running on Windows doesn't help…

Can you try adding these two lines and re-running? It should print two extra lines with the filename and “file URI” before failing.

diff --git a/zxing/__init__.py b/zxing/__init__.py
index bd0dd31..c767f0a 100644
--- a/zxing/__init__.py
+++ b/zxing/__init__.py
@@ -58,7 +58,9 @@ class BarCodeReader(object):
         elif stdout.startswith(b'''Exception in thread "main" java.io.IOException: Could not load '''):
             raise BarCodeReaderException("Java library could not read image; is it in a supported format?", filename)
         elif stdout.startswith(b'''Exception '''):
+            print(filename)
+            print(file_uri)
             raise BarCodeReaderException("Unknown Java exception: %s" % stdout)
         elif p.returncode:
             raise BarCodeReaderException("Unexpected subprocess return code %d" % p.returncode, self.java)

@vladvrabie
Copy link

vladvrabie commented Mar 17, 2020

I had the same problem (I'm also on Windows). I got the package through pip and I saw that there are some differences in __init__.py compared to the one on github.

My downloaded __init__.py had in the decode method:
file_uri = 'file://' + quote(os.path.abspath(filename))

While on github it looks like this (link):
file_uri = pathlib.Path(filename).absolute().as_uri()

The version on github worked for me.

file_uri variable value in 1st case: file://D%3A%5Czxing_test%5Cimage.jpg
file_uri variable value in 2nd case: file:///D:/zxing_test/image.jpg

Maybe something needs to be updated on pypi?

@dlenski
Copy link
Owner

dlenski commented Mar 17, 2020

The version on github worked for me.

I appreciate the feedback about the working change, but your way of demonstrating the difference is a little excruciating. 😓

A simple git log v0.10..HEAD will show you that we changed this in 06ce16c.

Maybe something needs to be updated on pypi?

Indeed. The aforementioned changes haven't yet been rolled into a release.

Update: Done. Latest version tagged as v0.11 and pushed to PyPI.

@dlenski dlenski closed this as completed Mar 20, 2020
Repository owner locked and limited conversation to collaborators Aug 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants