I have the latest QGIS 2.18.6 and i try to use some postgis query using python in QGS python console.
field characters from mytable is my non-English language and in postgis have encode 'utf-8' and any time where I want to work In QGIS never haven't problem with characters encode.
but any time to use python and postgis I have any time problem with encode characters.
here the code :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from qgis.PyQt.QtXml import QDomDocument
from qgis.utils import iface
import psycopg2
constring = u"dbname='database' host='postgre' port='port' user='username' password='code'"
conn=psycopg2.connect(constring)
checkCur = conn.cursor()
sqlCheck = "select * from public.mytable;"
checkCur.execute(sqlCheck)
sqlCheckRess = checkCur.fetchall()
mylist=[]
for i in sqlCheckRess :
mylist.append(i)
checkCur.close()
conn.close()
print mylist
that work nice but that I take in print mylist is un-humanity language
print like this :
u'2247_\u03a5\u06c6\u03b9\u04c3\u03c4\u03ac\u05bc\u03b5\u03bd\u03bf \u03c5\u03c0\u03cc\u03b2\u03b1
s = u'2247_\u03a5\u06c6\u03b9\u04c3\u03c4\u03ac\u05bc\u03b5\u03bd\u03bf \u03c5\u03c0\u03cc\u03b2\u03b1'
andprint s
return me2247_ΥۆιӃτάּενο υπόβα
It's just how the string it's store.