Encoding error after converting application into executable using py2exe and getting them from mysql (pySide, Python 3) -
i have application runs if run in directly python. however, after turn executable using py2exe encoding "breaks".
i run code gets string "comitê" mysql server. if run code:
frommysql = getfrommysql() local = "comitê" print(frommysql) print(local)
and save 2 files, 1 running directly python, other after compiling py2exe, following results:
from python: using sublime text 3 -> reopen encoding -> utf-8: comit? comit? using sublime text 3 -> reopen encoding -> western (iso 8859-1): comitê comitê after py2exe: using sublime text 3 -> reopen encoding -> utf-8: comit? comitê using sublime text 3 -> reopen encoding -> western (iso 8859-1): comitê comitê
it's worth noting in beginning of files have:
# -*- coding: utf-8 -*-
the code (removing unimportant bits):
main window code:
# -*- coding: utf-8 -*- import sys import pyside.qtgui qtgui ui.mainwindowcomite_ui import ui_mainwindowcomite import login import connector con class mainwindow(qtgui.qmainwindow, ui_mainwindowcomite): def __init__(self, parent=none): qtgui.qmainwindow.__init__(self, parent) self.ui = ui_mainwindowcomite.setupui(self, self) self.actioncadastro.triggered.connect(self.abrircadastro) self.actiondelegacao.triggered.connect(self.abrirdelegacao) self.actionacompanhamento.triggered.connect(self.abriracompanhamento) self.actioninvestigacao.triggered.connect(self.abririnvestigacao) self.actionhistorico.triggered.connect(self.abrirhistorico) self.login() def login(self): self.logindialog = login.login(self) self.logindialog.setmodal(true) self.logindialog.show() self.logindialog.rejected.connect(self.close) self.logindialog.accepted.connect(self.autenticado) def autenticado(self): self.setor = self.logindialog.setor print(self.setor) print("comitê") if self.setor != "comitê": qtgui.qmessagebox.information(self, u"erro", u"esta versão programa só pode ser utilizada pelo comitê") self.close() def closeevent(self, event): con.close() event.accept() if __name__ == '__main__': print("testê") app = qtgui.qapplication(sys.argv) window = mainwindow() window.show() sys.exit(app.exec_())
the login class:
import pyside.qtgui qtgui import sys ui.login_ui import ui_login import connector con class login(qtgui.qdialog, ui_login): def __init__(self, parent=none): qtgui.qdialog.__init__(self, parent) self.ui = ui_login.setupui(self, self) def accept(self, *args, **kwargs): self.setor = con.autenticar(self.setorlineedit.text(), self.senhalineedit.text()) if self.setor not none: self.setor = self.setor["setor"] if self.setor not none: qtgui.qdialog.accept(self) else: qtgui.qmessagebox.information(self, "falha", "tente novamente, setor ou senha errada")
the connector class:
# -*- coding: utf-8 -*- import datetime import pymysql def autenticar(login, senha): query = "select setor setores " \ "where login='%s' , senha='%s'" % (login, senha) execute(query) setor = cur.fetchall() return setor[0] if len(setor)>0 else none def connect(): global cur, con con = pymysql.connect('localhost', 'root', '', 'database', autocommit=true) cur = con.cursor(pymysql.cursors.dictcursor) def execute(query): try: cur.execute(query) except exception e: if str(e)[1:5] == '2013': # lost connection server cur.close() con.close() connect() cur.execute(query) else: raise e def close(): cur.close() con.close() connect()
Comments
Post a Comment