Bonjour a tous,
j'ai quelque problème avec des caractères unicode dans mes string.
En faite, j'ai un script qui génère un fichier html a partir d'un log svn en xml.
Dans l'un des commit, j'ai un caractère unicode.

voici l'erreur que j'obtiens
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
Traceback (most recent call last):
  File "./svn_External_bat/createHtmlSvnLog.py", line 104, in <module>
    compute(sys.argv[1],sys.argv[2],' '.join(sys.argv[3:]))
  File "./svn_External_bat/createHtmlSvnLog.py", line 99, in compute
    insertTologFile(html,outputFile)
  File "./svn_External_bat/createHtmlSvnLog.py", line 81, in insertTologFile
    contentFile=contentFile.encode("utf-8") 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)

voici le code qui pose problème
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
 
def convertXmlLogToHtml(xml,version):
    doc=parseString(xml)
    root=doc.documentElement
 
    strDate=datetime.today().strftime("%d/%m/%Y at %HH%M")
 
    htmlOutput="\n\t\t<div class='section' id='{0}'>\n\t\t\t<div class='headSection'>\n\t\t\t\t<h2>{0} - {1}</h2>\n\t\t\t</div>\n".format(version,strDate)
 
    for messageNode in root.getElementsByTagName('msg'):
        if len(messageNode.childNodes) > 0:
            msg=messageNode.childNodes[0].nodeValue
            msg=re.sub("(?P<link>http:[^\\s]+)","<a href='\g<link>'>\g<link></a> ",msg)
            htmlOutput+="\t\t\t<hr class='minHr'/>\n\t\t\t<p>\n\t\t\t\t"
            htmlOutput+=msg.replace("\n","<br/>")
            htmlOutput+="<br/><br/>\n\t\t\t</p>\n"
 
 
    htmlOutput+="\t\t</div>\n"
    return htmlOutput
 
def insertTologFile(content,outputFile):
    with open(outputFile, "r") as fichier:
        contentFile=fichier.read()
 
    try:   
        contentFile=unicode(contentFile,'utf-8')  
        content=unicode(content,'utf-8')  
    except TypeError:
        pass
 
    content=re.sub("</h1>","</h1>{0}".format(content),contentFile)
    with open(outputFile,"w") as fichier:
        fichier.write( codecs.BOM_UTF8 )
        fichier.write(content)
Savez vous comment je peux résoudre ce problème ?
Je vous remercie par avance pour votre aide