Bonjour, j'ai un probleme de codage avec le mysql.connector.2.0.3
lle cursor de mysql.connector renvoi un tuble de type bytearray(ok c bon je le decoder avec decode("utf-8")), mais l'orsque je execute mon projet depuis un autre pc qui a le meme version logiciels(Python , Mysql et mysql.connector2.0.3) il me renvoi un tuble de type Str, et il m'affiche un problème que le type str n'a pas un attribut decode("utf-8")(cette probleme est resolue quand j'ai illuminer le decode("Utf-8") ). Alors j'aime bien savoir l’origine de cette problème et savoir une solution pour me donne le mème resulta sur le deux PC.
les deuc pc on le meme verion logiciels(windows7 64bit, python4.3.2, mysql 5.6.17(encodeage 'Utf-8'), mysql.connector 2.0.3).
voila mon script
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: Utf-8 -*-
from tkinter import *
from tkinter.ttk import *
import mysql.connector
 
class consulter(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)   
 
        self.parent = parent
 
        self.initUI()
 
    def initUI(self):
        self.pack()
        db = mysql.connector.connect(host="localhost",user="root",password="",database="stock")
        cursor = db.cursor()
        cursor.execute("SELECT * FROM produit")
        results = cursor.fetchall()
        sb = Scrollbar(self, orient=VERTICAL)
        sb.pack(side=RIGHT, fill=Y)
        lbox=Treeview(self,yscrollcommand=sb.set)
        sb.configure(command=lbox.yview)
 
        lbox['columns']=("a","b","c","d")
        lbox.column("#0", anchor="w",width=50)
        lbox.heading("#0", text='Num')
        lbox.heading("a",text="Code")
        lbox.column("a",minwidth=100,width=100)
        lbox.heading("b", text="Nom")
        lbox.column("b",minwidth=100,width=200)
        lbox.heading("c", text="Quantité")
        lbox.column("c",minwidth=0,width=100)
        lbox.heading("d", text="Prix")
        lbox.column("d",minwidth=100,width=100)
        i=1
        for r in results:
            lbox.insert("","end",0,text=i,values=(r))
            i+=1
        lbox.pack()
 
        db.close()