3liz / QgisCadastrePlugin

A QGIS plugin which helps users to import the french land registry ('cadastre') data into a database. It is meant to ease the use of the data in QGIS by providing search tools and appropriate layer symbology.
GNU General Public License v2.0
60 stars 41 forks source link

Erreur : Recherche par lieux v1.4.1 #100

Closed tevrard closed 5 years ago

tevrard commented 7 years ago

Bonjour,

Je rencontre l'erreur suivante lorsque je fais une "Recherche par lieux" avec le panneau de recherche, plus précisément lors du choix de la section :

Code:
2017-03-03T08:25:54 1   Traceback (most recent call last):            File "C:/Users/tevrard/.qgis2/python/plugins\cadastre\cadastre_dialogs.py", line 1887, in onNonSearchItemChoose
                self.setupSearchCombobox(ckey, filterExpression, 'sql')
              File "C:/Users/tevrard/.qgis2/python/plugins\cadastre\cadastre_dialogs.py", line 1570, in setupSearchCombobox
                self.searchComboBoxes[combo]['orderBy']
              File "C:/Users/tevrard/.qgis2/python/plugins\cadastre\cadastre_dialogs.py", line 1661, in getFeaturesFromSqlQuery
                [header, data, rowCount, ok] = cadastre_common.fetchDataFromSqlQuery(connector, sql)
              File "C:/Users/tevrard/.qgis2/python/plugins\cadastre\cadastre_dialogs.py", line 480, in fetchDataFromSqlQuery
                print e.msg
            UnicodeEncodeError: 'ascii' codec can't encode character u'\xab' in position 20: ordinal not in range(128)

Précisions :

-Le reste des fonctions, notamment l'outil "info parcelles", semblent fonctionner normalement

mdouchin commented 7 years ago

En effet, les outils de recherche ne fonctionnent pour l'instant que si des données MAJIC sont présentes dans la base.

rldhont commented 7 years ago

Une amélioration a été intégré 65ec418ba1e7f835833372989fc8b1804fc3f993 et sera disponible dans la version 1.4.2 qui sera bientôt publiée.

MaelREBOUX commented 5 years ago

Bonjour @tevrard

Est-ce que ce problème est toujours d'actualité ou peut-on clore ce ticket ?

en lien avec #99

tevrard commented 5 years ago

Bonjour,

Le ticket peut être clos.

Merci du suivi !

----- Mail original -----

De: "Maël REBOUX" notifications@github.com À: "3liz/QgisCadastrePlugin" QgisCadastrePlugin@noreply.github.com Cc: "tevrard" thom.evrard@laposte.net, "Mention" mention@noreply.github.com Envoyé: Lundi 19 Août 2019 11:27:13 Objet: Re: [3liz/QgisCadastrePlugin] Erreur : Recherche par lieux v1.4.1 (#100)

Bonjour @tevrard

Est-ce que ce problème est toujours d'actualité ou peut-on clore ce ticket ?

en lien avec #99

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub , or mute the thread .

boillodmanuel commented 3 years ago

Bonjour, J'ai rencontré un problème similaire : UnicodeDecodeError: 'ascii' codec can't decode Mon env :

J'ai fini par trouver comment corriger mon problème (la résolution de celui-ci est peut-être similaire)

Dans le fichier cadastre_import.py, fonction replaceParametersInScript, il manque l'encoding sur cette ligne : https://github.com/3liz/QgisCadastrePlugin/blob/2b2c0e3affcf67b49c88bda31f54cdb3b904a617/cadastre/cadastre_import.py#L1015-L1016

Voici le fix:

with open(scriptPath, 'w', encoding='utf-8') as fout:
    fout.write(data)

La locale système ne doit pas être configuré comme il faut dans QGIS. Pour le vérifier, j'ai ouvert la console python (Plugins > Console Python) et exécuté le code suivant :

# Explicitly open with ascii encoding:
# ❌ Error:
#   UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in position 0: ordinal not in range(128)
with open('/tmp/test', 'w', encoding='ascii') as fout:
    fout.write(u"\u2122")

# Open without encoding specified:
# ❌ Error or ✅ Works depending of system locale :
#   UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in position 0: ordinal not in range(128)
with open('/tmp/test', 'w') as fout:
    fout.write(u"\u2122")

# Explicitly open with utf-8 encoding:
# ✅ Works
with open('/tmp/test', 'w', encoding='utf-8') as fout:
    fout.write(u"\u2122")

Pour forcer la locale dans QGIS, j'ai ajouté la variable d'environnement LC_ALL dans les préférences (interface en anglais) :.

Je ne suis pas sûr qu'il faille garder ce paramétrage mais ca aide pour débugger.