logo       

Re: Coding when open conection: msg#00041

python.db.psycopg.devel

Subject: Re: Coding when open conection

Markus Bertheau escribió:
В Птн, 10/03/2006 в 11:12 +0100, Oswaldo Hernández пишет:


I try to connect with a bad user with PgAdminIII and EMS and both show the
message correctly.
Hereby I suppose that the problem is that psycopg2 don't use utt8 until set_client_encoding is sended, and the message is received before it.


So error messages after that don't cause failure and correctly display «
and »?



Opps, I provoke an integrity error after connect and send client encoding and
also do the error:

# -*- coding: UTF8 -*-
import psycopg2 as pg
import sys
import wx

app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()

try:
# these are correct database and user, the conection do ok
pgcon = pg.connect("dbname=soft-com user=postgres")
except:
ex = "Exception:\n%s\n(%s)" % (sys.exc_info()[1], sys.exc_info()[0])
# print don't cause error
print ex
wx.MessageDialog(None, ex, '', wx.ICON_ERROR | wx.OK).ShowModal()
sys.exit()

# message with « and » chars, shows good
wx.MessageDialog(None, " « Connection OK »", '', wx.ICON_ERROR |
wx.OK).ShowModal()
pgcon.set_client_encoding('UTF8')

try:
# -> this execute cause an integrity error <-
pgcon.cursor().execute("delete from pruebas.prueba1 where serie ='a' and numero
= 1")
except:
ex = "Exception:\n%s\n(%s)" % (sys.exc_info()[1], sys.exc_info()[0])
# print don't cause error
print ex
# ---> when try to show this dialog the error is generated
dlg = wx.MessageDialog(None, ex, '', wx.ICON_ERROR | wx.OK).ShowModal()

sys.exit()

the output is:

Exception:
update o delete en ½prueba1╗ viola la llave forßnea ½fkprueba1╗ en
½prueba1cuerpo╗
DETAIL: La llave (serie,numero)=(a,1) todavÝa es referida desde la tabla
½prueba1cuerpo╗.

(psycopg2.IntegrityError)
Traceback (most recent call last):
File "X:\Python\scLib\perror.py", line 31, in ?
dlg = wx.MessageDialog(None, ex, '', wx.ICON_ERROR | wx.OK).ShowModal()
File "C:\Python24\lib\site-packages\wx-2.6-msw-unicode\wx\_windows.py", line
3030, in __init__
newobj = _windows_.new_MessageDialog(*args, **kwargs)
File "C:\Python24\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xab in position 30:
unexpected code byte


I'm confused, I can save and retrieve data with these chars without problems.



--
*****************************************
Oswaldo Hernández
oswaldo-aXkDUzFGsCcxAGwisGp4zA@xxxxxxxxxxxxxxxx
*****************************************


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise