Execute and distribute unicode problem

#1

Hi,
I send a report by email using run script Schedule. I use executeAndDistribute function in the script.
When I receive my email, special char appear in the body when my attachment name include special char like “é”,“â”.
I’ve tried to encode in utf8 but it’s not working.
Do you have a solution ?

Thanks

0 Likes

#2

I would guess the gateway itself needs to be set to use a utf8 locale.

0 Likes

#3

Can you compare the binary representations of the letters you received and the letters you wanted? Then you can usually find out from what to what encoding it was converted, and what you have to look for.

I’d like to look it up myself, but I can’t copy-paste from an e-mail, and I can’t type those characters either.

0 Likes

#4

For example :
鮥 instead of “éne”
鴩 instead of “éti”
鱵 instead of “équ”

How can I set the gateway to UTF8 ?

Thanks

0 Likes

#5

What version of Ignition are you using?

Can you paste the lines of script where you define your attachment name and where you call executeAndDistribute?

0 Likes

#6

My code below :

# On va chercher les id et noms des databases actives
	databases=system.db.runQuery("SELECT id,name,title,station FROM ignition_projects WHERE reportEnable = 1")
	
	body=u"""Madame, Monsieur,\r\rNous vous adressons cet email dans le cadre du monitoring énergétique, qui équipe la résidence en référence (cf. titre de la pièce jointe).\r
		Vous trouverez ci-joint le suivi hebdomadaire de performance du chauffage, pour la période allant du """+str(system.date.format(dataMap['sem4StartDate'], "dd-MM-yyyy"))+""" au """+str(system.date.format(dataMap['sem4EndDate'], "dd-MM-yyyy"))+u""" inclus.\r
		Sur cette période et en fonction des seuils positionnés, des messages d'alerte ont pu être adressés et sont détaillés en 3e page.\r\r
		Restant en vigilance pour la résidence,\r\r
		CET EMAIL EST GÉNÉRÉ AUTOMATIQUEMENT MERCI DE NE PAS Y RÉPONDRE"""
	
	for db in databases:
		
	
		#Pour chaque database on va récupérer les emails des utilisateurs (ignition_user_projects JOIN ignition_user_ci)
		emails=["my@email.fr"]
		
		#heatingState=system.db.runQuery("SELECT valueBool FROM heating_contract WHERE name='heatingState'","test")[0][0]
		heatingState=1
		
		
		#Les variables d'entrées du rapport
		reportParameters = {"projectName":db['title'],"database":db['name'],"station":db['station']}
		subject=db['title']+" - Suivi hebdomadaire de performance du chauffage"
		attachmentName=db['title']+" - Suivi hebdomadaire de performance du chauffage - "+str(system.date.format(system.date.now(), "yyyy-MM-dd"))+".pdf"
		 
		
		if heatingState==1:
			system.report.executeAndDistribute(path="WeekReportV2", project="home", action= "email", parameters=reportParameters ,
			actionSettings = {"to":emails, "smtpServerName":"SMTP", "from":"noreply@email.fr", "subject":subject,"body":body,"attachmentName":attachmentName})
0 Likes

#7

Using previous code, I receive email below :
BODY :

Madame, Monsieur,

Nous vous adressons cet email dans le cadre du monitoring énergétique, qui équipe la résidence en référence (cf. titre de la pièce jointe).
Vous trouverez ci-joint le suivi hebdomadaire de performance du chauffage, pour la période allant du 23-09-2019 au 29-09-2019 inclus.
Sur cette période et en fonction des seuils positionnés, des messages d'alerte ont pu être adressés et sont détaillés en 3e page.

Restant en vigilance pour la résidence,

CET EMAIL EST GÉNÉRÉ AUTOMATIQUEMENT MERCI DE NE PAS Y RÉPONDRE

0 Likes

#8

This sounds exactly like a problem that was fixed in 7.9.5, which is why I was hoping to find out what version you’re using. (FB9167 for other IA employees looking here)

0 Likes

#10

My version is 7.9.9 (b2018081621)

0 Likes

#11

Thanks. I’ll see if we can replicate this here

0 Likes

#12

Maybe this could help you.

As our native language is spanish, We have problems with special characters often (á, é, ¿, etc).

To solve this problem, in scripting context (python) we put an “u” before the string it self.

For example:

text1 = u'¿Desea aplicar la confirmación?'

The “u” is for “unicode” if i remember correctly
Hope this help you. Greetings

0 Likes

#13

I’ve already do that. It didn’t work.

0 Likes

#14

I’d try to write the email body in execution context (just for testing purposes) and in the script context get the text with “body_text = event.source.text” or something like that. Then, if the email still shows the special characters like garbage, I think that the problem is with the email generation.

Do you have the same results with this function “system.net.sendEmail”?

0 Likes

#15

@apimente I’ve already replicated the problem and it’s a bug that’s happening with system.report.executeAndDistribute() but is not happening with system.net.sendEmail().

@flavien Until we get a fix, the workaround is use system.report.executeReport() to get the bytes from the report, and attach those to an email you send with system.net.sendEmail()

0 Likes

#16

Thanks.
How can I send my report with system.net.sendEmail function using my variable reportParameters ?
It’s a dynamic report.

0 Likes

#17

You create your dynamic report using executeReport() [docs], which returns the PDF of the report. Then those bytes are an attachment for your email.

1 Like

#18

It works good. My email body use unicode but attachment name and subject still not working.
image
The code below

subject=db['title'].encode('utf-8')+u" - Suivi hebdomadaire de performance du chauffage"
attachmentName=db['title'].encode('utf-8')+u" - Suivi hebdomadaire de performance du chauffage - "+system.date.format(system.date.now(), "yyyy-MM-dd")+u".pdf"
0 Likes

#19

Try this:

subject=unicode(db['title'])+u" - Suivi hebdomadaire de performance du chauffage"
attachmentName=unicode(db['title'])+u" - Suivi hebdomadaire de performance du chauffage - "+system.date.format(system.date.now(), "yyyy-MM-dd")+u".pdf"
0 Likes

#20

It’s not working. :cry:

0 Likes

#21

Since it’s working for me in Ignition 8, now we’re at the hard part of solving this. :slight_smile:

First, let’s try to cut the problem in half. Can you take the same script, but instead of creating an email, make the subject and attachment name show in a label in a Vision window? (Not the script console, which doesn’t always show unicode correctly). That will let us know that the characters are getting to the email correctly.

If the subject and attachment names show correctly in Vision, we want to find out what the gateway sees as the subject when it sends the email. This will take a little work, because we need to trigger a particular logging statement. (Note to self – we should improve the logging here) To do this, send your email to an obviously invalid user, which hopefully your SMTP server will reject rather than just quietly ignore. For example, user@thing (ie no .com at the end) might trigger this. Set the SMTP.Manager logger in the gateway to debug, make sure you use a retries value greater than 0, and hopefully we will see a logging statement telling you the email failed. That logging statement will include the subject of the email. You can filter down to that logger in the gateway to make it easier to find.

If the logging statement shows the correct subject, then this unicode failure is probably after the email leaves Ignition. You would need to check the settings on the SMTP server being used. (I’m assuming the email clients receiving the email normally show unicode subjects just fine.)

0 Likes