Problème Libellé date Unicode
Bonjour,
Suis débutant dans Phython.
Dans une édition OpenERP 6.1, dans la première colonne, est imprimer le mois en lettre et l'année.
Lorsque le mois comporte un accent (Février, Août, Décembre) le rapport plante pour cause de caractère Unicode non reconnu.
J'ai besoin de votre aide Urgente. merci
Voici le code:
-l'inisialisation :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
ym_desc = {}
for prod_data in prod_datas:
tdate = datetime.datetime.strptime(prod_data.date, '%Y-%m-%d')
ym = tdate.strftime('%Y-%m')
ore_cat = prod_data.ore_type_id.category
ore_code = prod_data.ore_type_id.code
volume = prod_data.volume_of_ore
weight = prod_data.weight_of_ore
if(ym not in ym_desc):
#check base/res/res_lang.py line 56-62
lang = context.get('lang','en_US')
for ln in tools.get_locales(lang):
try:
locale.setlocale(locale.LC_ALL, str(ln))
break
except locale.Error:
continue
#set month year description
ym_desc[ym] = tdate.strftime('%B %Y')
|
- Le code où cela plante
Code:
1 2 3 4 5 6 7 8 9
|
row_xml = { 'month' : [], 'ending' : [] }
for key, row in rows:
if key != 'ending':
tkey = 'month'
row_xml[tkey].append('<row monthYear="%s">' % (ym_desc[key]))
else:
tkey = 'ending'
row_xml[tkey].append('<row>') |
Enfin, l'erreur affichée:
Code:
1 2 3 4 5 6 7 8
|
utf8
<row monthYear="août 2014">
18
23
unsupported Unicode code range
(<type 'exceptions.UnicodeDecodeError'>, UnicodeDecodeError('utf8', '<row monthYear="ao\xfbt 2014">', 18, 23, 'unsupported Unicode code range'), <traceback object at 0x03AE3328>) |
J'ai essayé:
Code:
1 2 3
|
ym_utf8 = tdate.strftime('%B %Y')
ym_desc[ym] = unicode( ym_utf8 , 'utf-8') |
Mais sans succès.
Mille merci pour votre aide