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

New install in QGIS gives Python error UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 591: ordinal not in range(128) #50

Closed
leighghunt opened this issue Dec 19, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@leighghunt
Copy link

Entirely possible I'm missing something obvious here, but I just tried installing the QGIS Kart plugin, and I'm getting the following error in the Python error log when going to Plugins -> Kart -> About....

2021-12-20T11:37:56     WARNING    Traceback (most recent call last):
              File "/Users/leighhunt/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/kart/plugin.py", line 72, in openAbout
              pluginVersion = self.pluginVersion()
              File "/Users/leighhunt/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/kart/plugin.py", line 66, in pluginVersion
              config.read(path)
              File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/configparser.py", line 697, in read
              self._read(fp, filename)
              File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/configparser.py", line 1017, in _read
              for lineno, line in enumerate(fp, start=1):
              File "/Applications/QGIS.app/Contents/MacOS/lib/python3.8/encodings/ascii.py", line 26, in decode
              return codecs.ascii_decode(input, self.errors)[0]
             UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 591: ordinal not in range(128)

I then went to Plugins -> Kart -> Settings... and set Kart executable to /usr/local/bin/kart and get the following error in the Kart log:

2021-12-20T11:38:01     INFO    Command: Applications/Kart.app/Contents/MacOS/kart_cli --version
2021-12-20T11:38:01     CRITICAL    [Errno 2] No such file or directory: 'Applications/Kart.app/Contents/MacOS/kart_cli'

Further info:

QGIS Plugins log:

2021-12-20T11:44:50     INFO    Loaded QuickMapServices (package: quick_map_services)
2021-12-20T11:44:51     INFO    Loaded Relief Visualization Toolbox (package: rvt-qgis)
2021-12-20T11:44:53     INFO    Loaded Processing (package: processing)
2021-12-20T11:44:53     INFO    Loaded DB Manager (package: db_manager)
2021-12-20T11:44:53     INFO    Loaded MetaSearch Catalog Client (package: MetaSearch)
2021-12-20T11:45:09     INFO    Loaded Kart (package: kart)
which kart
/usr/local/bin/kart

kart --version
Kart v0.10.7, Copyright (c) Kart Contributors
» GDAL v3.3.2; PROJ v6.3.0
» PyGit2 v1.7.0; Libgit2 v1.3.0; Git v2.33.GIT
» SQLAlchemy v1.4.11; pysqlite3 v2.6.0/v3.31.1; SpatiaLite v5.0.1; Libpq v14.0.1
» SpatialIndex v1.9.3

kart_cli
zsh: command not found: kart_cli

Kart was installed using homebrew, OS: MacOSX Monterey, on MacBook Air with M1 chip. QGIS version 3.18.1-Zürich

More verbose error message when attempting to see Kart Settings again:

An error has occurred while executing Python code: 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 591: ordinal not in range(128) 
Traceback (most recent call last):
  File "/Users/leighhunt/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/kart/plugin.py", line 72, in openAbout
    pluginVersion = self.pluginVersion()
  File "/Users/leighhunt/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/kart/plugin.py", line 66, in pluginVersion
    config.read(path)
  File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/configparser.py", line 697, in read
    self._read(fp, filename)
  File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/configparser.py", line 1017, in _read
    for lineno, line in enumerate(fp, start=1):
  File "/Applications/QGIS.app/Contents/MacOS/lib/python3.8/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 591: ordinal not in range(128)


Python version: 3.8.7 (default, Feb 10 2021, 09:04:08) [Clang 12.0.0 (clang-1200.0.32.29)] 
QGIS version: 3.18.1-Zürich Zürich, 202f1bf7e5 

Python Path:
/Applications/QGIS.app/Contents/MacOS/../Resources/python
/Users/leighhunt/Library/Application Support/QGIS/QGIS3/profiles/default/python
/Users/leighhunt/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins
/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/patsy-0.5.1-py3.8.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/Rtree-0.9.4-py3.8.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/geopandas-0.8.1-py3.8.egg
/Applications/QGIS.app/Contents/MacOS/lib/python38.zip
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/rasterio-1.1.5-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/Fiona-1.8.13.post1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/click_plugins-1.1.1-py3.8.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/numpy-1.20.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/affine-2.3.0-py3.8.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/pandas-1.1.0-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/netCDF4-1.5.4-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/statsmodels-0.11.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/lib-dynload
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/cftime-1.2.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/pyproj-2.6.0-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/scipy-1.5.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/Pillow-7.2.0-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/numba-0.50.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/snuggs-1.4.7-py3.8.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/GDAL-3.2.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/matplotlib-3.3.0-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS.app/Contents/MacOS/lib/python3.8/site-packages/opencv_contrib_python-4.3.0.36-py3.8-macosx-10.13.0-x86_64.egg
/Users/leighhunt/Library/Application Support/QGIS/QGIS3/profiles/default/python
/Users/leighhunt/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/rvt-qgis
/Users/leighhunt/dev/playground/covid/covid-geojson
@craigds craigds transferred this issue from koordinates/kart Dec 19, 2021
@rcoup
Copy link
Member

rcoup commented Dec 20, 2021

Non-ascii character was removed in b28dda6, but https://github.com/koordinates/kart-qgis-plugin/blob/main/kart/plugin.py#L66 should probably call .read(..., encoding='utf-8')? AFAICS QGIS opens metadata as UTF8.

@rcoup
Copy link
Member

rcoup commented Dec 20, 2021

@volaya

  1. can we change kartExecutable() to start with shutil.which('kart') first, and then fall back to the default paths? On Linux & macOS we by default put a symlink in /usr/bin/ or /usr/local/bin/, and on Windows by default we add to the system path, so kart by itself will generally Just Work™. Ah... I have vague recollections we already did this and QGIS messes with the system path?

  2. Regardless, the default macOS path in https://github.com/koordinates/kart-qgis-plugin/blob/main/kart/kartapi.py#L84 is missing a leading /.

@rcoup rcoup added the bug Something isn't working label Dec 20, 2021
@rcoup
Copy link
Member

rcoup commented Dec 21, 2021

Ah... I have vague recollections we already did this and QGIS messes with the system path?

A: yes, it resets the environment as seen by the QGIS Python Interpreter.

$ python3 -c 'import shutil; print(shutil.which("kart"))'
/usr/local/bin/kart

QGIS Python Console:

>>> import shutil
>>> print(shutil.which('kart'))
None
>>> import os
>>> os.environ['PATH']
'/usr/bin:/bin:/usr/sbin:/sbin'

@volaya volaya closed this as completed in 666dd80 Dec 21, 2021
@rcoup
Copy link
Member

rcoup commented Dec 21, 2021

Hi @leighghunt, the fix for this is released now in 1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants