Trouble with the 7.4.1 version about the string conversion

I have some trouble with the 7.4.1 version about the string conversion in many scripts afetr upgrading my server
My scripts was ok in 7.3.3 b570

I have some error in 7.4.1 when :

  • str() is executed on a string variable
  • when sql query return characters such as ‘ê’ or ‘é’
    see the following example executed in the script playground:
def htmlInfoPae(id_pae):
	import app.commun
	import system

	table = system.db.runPrepQuery("SELECT * from VUE_PAE_TERRITOIRE where id_pae=?",[id_pae],dbfrontal)
	html = "<HTML><HEAD><TITLE>PAE : " + str(id_pae) + "</TITLE></HEAD><BODY>"

	if len(table)==1:
		html = html + "PAE : " + str(id_pae) + "<BR>¤"
		[b]html = html + "Commune : " +  table[0]["COMMUNE"] + "<BR>"[/b]
		html = html + "</BODY></HTML>"	
		html = html + "PAE : " + str(id_pae) + "<BR><BR>Pas de détail ???"+ "</BODY></HTML>"	
	return (html)

import sys
#print sys.getdefaultencoding()
#print "¤" + " téêst " + "¤"
print htmlInfoPae(1)

the error message (for the line in bold)

The problem is you are trying to print the ascii characters out and some characters are unicode. You can do the following for the print statement:print htmlInfoPae(1).encode('ascii', 'replace')which will put ? for every unknown ascii character. If you save it to a file or something it should be fine.

We did upgrade Jython in 7.4 which is why it may have worked in 7.3.

thank for your help
I found a solution with these actions on my 7.3.3 scripts for a compatibility in 7.4.1

suppress the str() cast on string variable (it generated an exception if string containt non ascii character)
replace instruction like "Arrêt " + table[0] with [b]u[/b]"Arrêt " + table[0]


replace :

"Arrêt " + table[0]

with :

u"Arrêt " + table[0]

prefix all the non-ascii or extended ascii const string with u"" !

Thanks for posting the solution!