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

accentued caracters make problem to load python expression script #27567

Closed
qgib opened this issue Aug 31, 2018 · 9 comments
Closed

accentued caracters make problem to load python expression script #27567

qgib opened this issue Aug 31, 2018 · 9 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions Feedback Waiting on the submitter for answers stale Uh oh! Seems this work is abandoned, and the PR is about to close.

Comments

@qgib
Copy link
Contributor

qgib commented Aug 31, 2018

Author Name: Jérôme Seigneuret (Jérôme Seigneuret)
Original Redmine Issue: 19742
Affected QGIS version: 3.2.2
Redmine category:expressions


Hi,

Error

2018-08-31T15:05:56 WARNING L'expression de l'utilisateur base_water_function n'est pas valide
Traceback (most recent call last):
File "C:/OSGEO41/apps/qgis/./python\qgis\user.py", line 48, in load_user_expressions
import("expressions.{0}".format(name), locals(), globals())
File "C:/OSGEO4
1/apps/qgis/./python\qgis\utils.py", line 674, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:/Users/user1/AppData/Roaming/QGIS/QGIS3\profiles\default/python\expressions\base_water_function.py", line 21
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xe9 in position 4: invalid continuation byte

Context:

I make a function in expresion script panel and it is used to set label.

The expression script is:


1. -*- coding: utf-8 -*-
from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def get_pipe_material_code_fr(v,feature, parent):
    """
    return french material name  to it corresponding code
    """
    if v == "Fonte":
        return "F"
    elif v == "Pvc":
        return "PVC"
    elif v == "inconnu":
        return "?"
    elif v == "Polyéthylène": 
        return "PE"
    else:
        return "X"

In fact i see
C:\Users\user1\AppData\Roaming\QGIS\QGIS3\profiles\default\QGIS\QGIS3.ini
encoding=UTF-8

there is no information with python but if I have understand, QGIS 3 work with python 3 and default encoding is UTF-8 so I don't understrand

my label call get_pipe_material_code_fr("Material") || (' Ø' ) || "Diameter"

If I go in function panel and click on load, all work fine.

Software information

Version de QGIS
3.2.2-Bonn
Révision du code
2684216
Compilé avec Qt
5.9.2
Utilisant Qt
5.9.2
Compilé avec GDAL/OGR
2.2.4
Utilisé avec GDAL/OGR
2.2.4
Compilé avec GEOS
3.6.1-CAPI-1.10.1
Utilisé avec GEOS
3.6.1-CAPI-1.10.1 r0
Version du client PostgreSQL
9.2.4
Version de SpatiaLite
4.3.0
Version de QWT
6.1.3
Version de QScintilla2
2.10.1
Version de PROJ.4 :
493

@qgib
Copy link
Contributor Author

qgib commented Aug 31, 2018

Author Name: Giovanni Manghi (@gioman)


  • category_id was changed from Unknown to Expressions

@qgib
Copy link
Contributor Author

qgib commented Sep 3, 2018

Author Name: Jérôme Seigneuret (Jérôme Seigneuret)


This error are caused by encoding file...

I have create expression in an old version and I don't understand why but file is in ANSI and not utf-8. I convert encoding with Notepad++ and all work fine.

It's possible to add analyse on encoding file if it's not identical to header declaration or/and default encoding?


  • status_id was changed from Open to Closed

@qgib
Copy link
Contributor Author

qgib commented Sep 3, 2018

Author Name: Giovanni Manghi (@gioman)


  • resolution was changed from to invalid

@qgib
Copy link
Contributor Author

qgib commented Sep 3, 2018

Author Name: Harrissou Santanna (@DelazJ)


2018-08-31T15:05:56 WARNING L'expression de l'utilisateur base_water_function n'est pas valide

L'utilisateur s'appelle base_water_function ou c'est une mauvaise traduction et c'est plutôt le nom de la fonction?

@qgib
Copy link
Contributor Author

qgib commented Sep 3, 2018

Author Name: Jérôme Seigneuret (Jérôme Seigneuret)


Harrissou Santanna wrote:

2018-08-31T15:05:56 WARNING L'expression de l'utilisateur base_water_function n'est pas valide

L'utilisateur s'appelle base_water_function ou c'est une mauvaise traduction et c'est plutôt le nom de la fonction?

Sorry for french resume but I think this is an error of translation same as @Harrissou

Il y a peut être une erreur de traduction. En fait je dirais :

"Le fichier d'expression utilisateur base_water_function n'est pas valide"

File have same name as user expression file listed in fonction (normaly) but there is really a problem because ther is no analyse to check if name are valid or not with file system. I think this message need to be a new issue.

\ is a valide expression file name! file stored ... I don't no where because there is no file in folder
// is a valide expression file name! file stored is .py

@qgib
Copy link
Contributor Author

qgib commented Sep 3, 2018

Author Name: Jérôme Seigneuret (Jérôme Seigneuret)


I understand why my fucntion don't work

When I load function file it is save in local encoding and not in utf-8

so when I reopen it on notepad++ this looks like to that


1. -*- coding: utf-8 -*-
from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def get_pipe_material_code_fr(v,feature, parent):
    """
    read and replace value by code
    """
    if v == "Fonte":
        return "F"
    elif v == "Pvc":
        return "PVC"
    elif v == "inconnu":
        return "?"
    elif v == "Poly굨yl鯥":
        return "PE"
    else:
        return "X"


This comportment is on all scripts... But not all my script contains non ascii caracters. This is the why I don't detect that before


  • status_id was changed from Closed to Reopened

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions labels May 25, 2019
@alexbruy
Copy link
Contributor

Can be closed?

@alexbruy alexbruy added the Feedback Waiting on the submitter for answers label Apr 19, 2020
@github-actions
Copy link

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale".
If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue.
In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue.
If there is no further activity on this issue, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jan 24, 2021
@github-actions
Copy link

While we hate to see this happen, this Issue has been automatically closed because it has not had any activity in the last 42 days despite being marked as feedback. If this issue should be reconsidered, please follow the guidelines in the previous comment and reopen this issue.
Or, if you have any further questions, there are also further support channels that can help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions Feedback Waiting on the submitter for answers stale Uh oh! Seems this work is abandoned, and the PR is about to close.
Projects
None yet
Development

No branches or pull requests

2 participants