Bug report #16756

Encoding error in DB Manager

Added by Julien Sabatier over 7 years ago. Updated about 7 years ago.

Status:Closed
Priority:High
Assignee:-
Category:DB Manager
Affected QGIS version:2.18.10 Regression?:Yes
Operating System:Debian, Windows Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:24655

Description

Since this 14ab5eb0bda9a5993b9ab15a3b7de1af9df8dcba

I get this error when trying to import data via 'cadastre' module in a PostGIS database :

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 104: ordinal not in range(128) 
Traceback (most recent call last):
  File "C:/Users/julien.sabatier/.qgis2/python/plugins\cadastre\cadastre_dialogs.py", line 1090, in processImport
    qi.importMajic()
  File "C:/Users/julien.sabatier/.qgis2/python/plugins\cadastre\cadastre_import.py", line 419, in importMajic
    self.executeSqlScript(s, False, item.has_key('constraints'))
  File "C:/Users/julien.sabatier/.qgis2/python/plugins\cadastre\cadastre_import.py", line 1064, in executeSqlScript
    self.executeSqlQuery(sql, ignoreError)
  File "C:/Users/julien.sabatier/.qgis2/python/plugins\cadastre\cadastre_import.py", line 1115, in executeSqlQuery
    c = self.connector._execute_and_commit(sql)
  File "C:/PROGRA~1/QGIS2~1.18/apps/qgis/./python/plugins\db_manager\db_plugins\connector.py", line 95, in _execute_and_commit
    self._execute(None, sql)
  File "C:/PROGRA~1/QGIS2~1.18/apps/qgis/./python/plugins\db_manager\db_plugins\connector.py", line 81, in _execute
    cursor.execute(str(sql))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 104: ordinal not in range(128)

Version de Python : 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] 
Version de QGIS : 2.18.10 Las Palmas, 59e0f78 

It look like the use of the str function in the connector create this error.

Have you some solution to fix this ? Is it a configuration problem with my environment ?
I tried both on a Debian and Windows platform and each time with the 2.18 version of QGis I have this error.

History

#1 Updated by Martin HOFFMANN over 7 years ago

Hello, I opened an issue #16833 that might also be linked to this bug, can you try reproduce on your side?

Sorry if I posted in the wrong place, I'm more a user than a developer :/

#2 Updated by Giovanni Manghi over 7 years ago

  • Subject changed from Encoding error in db_manager/db_plugin to Encoding error in DB Manager
  • Affected QGIS version changed from master to 2.18.10
  • Easy fix? changed from Yes to No

#3 Updated by Giovanni Manghi over 7 years ago

  • Status changed from Open to Feedback

Can you please describe the steps to follow in order to replicate? I'm not familiar with the "cadastre" module (plugin?). Thanks!

#4 Updated by Julien Sabatier over 7 years ago

Giovanni Manghi wrote:

Can you please describe the steps to follow in order to replicate? I'm not familiar with the "cadastre" module (plugin?). Thanks!

I don't think that you can reproduce it easily as files needed to import data are privates one, their access is restricted to public administration because they includes data on parcels owners.

Actually the developpers of this module work on a patch to handle this bug at the module level : https://github.com/3liz/QgisCadastrePlugin/issues/106

#5 Updated by Giovanni Manghi over 7 years ago

Actually the developpers of this module work on a patch to handle this bug at the module level : https://github.com/3liz/QgisCadastrePlugin/issues/106

so the developer of "cadastre" thinks is a "cadastre" issue and not a DB Manager one?

#6 Updated by Julien Sabatier over 7 years ago

Yes, they wrote a patch for use encode('utf-8') at the module level, that make sense as the module is responsible of the data he import.

https://github.com/3liz/QgisCadastrePlugin/commit/58beda12cbd454b98b6c07453f7a2a559ed58a71

#7 Updated by Giovanni Manghi over 7 years ago

  • Status changed from Feedback to Closed
  • Resolution set to invalid

*

#8 Updated by Jürgen Fischer about 7 years ago

  • Description updated (diff)

Also available in: Atom PDF