[SOLVED] character encoding error

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

December 4, 2017 - 10:14 AM

Good morning,

I am trying to create a temporary file for a new package using the import tempfile function.
I define the content of my temporary file as follows:

Code: Select all

data = ur"""moncontenu"""
During package installation, I get the following error: 'ascii' codec can't encode character
I deduce that it doesn't like certain characters in my temp file...

Is there a solution?

THANKS
Last edited by olaplanche on Dec 11, 2017 - 2:52 PM, edited 1 time.
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

December 4, 2017 - 11:09 AM

Hello

, unless it's sensitive, is it possible to get the full code?

Simon
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

December 4, 2017 - 11:13

Good morning,

Here is the code minus the part concerning the software license:

Code: Select all

    import tempfile
    pathparamsfile = makepath(tempfile.gettempdir(),'Eureka.ini')
    data = ur"""[OEM]

[Langue]
Ressources=FR
Impression=FR




[Menus]
primo=1
Fichier=00010100011101
Edition=11111111000
Stade=01
Vues=1
Données=10100001
Insertion=111111111111111110001
Analyses=11110000
Affichage=1
Format=1
BOApplication=000000
BOApplicationSphinx=1101
BOInsertion=111101111101111
Interview=1
CS=CS
V51=1

[debug]
licenceur=\\data-svr1\outils$\Logiciels\SphinxV5\programmes\Licence\Licence.exe
ligne= -m=config -s=C:\Program Files (x86)\SphinxV5\sphinx.ini -e=C:\Program Files (x86)\SphinxV5\eureka.ini
[Fichiers]
Fichiers=Fichiers
Répertoires=dictionnaires ; Multimédia/Drapeaux ; Multimédia/Navigation ; Multimédia/Formes ; Multimédia/Fonds ; Multimédia/Images ; Multimédia/Pictos_ecran ; Multimédia/Pictos_papier ; Modelesinternet
Documents=Enquêtes
Multimédia=Multimédia
Mots-outils=dictionnaires\Mots-outils.dic
Styles=Styles.hys
SphinxOnline=http://www.sphinxonline.net
CompteTest=public
MotDePasseTest=Z7L
Comptes=
Abonnement=http://www.sphinxonline.com/abonnementFR.htm
Conseils=1;1;1
QualitéJPEG=100
EditionBasic=1
PropriétésObjets=0
Partage=0
Applet=EurekaApplet.jar
Conditions=http://www.sphinxonline.com/conditionsFR.htm
Fichier1=Enquêtes\Automobiles\Automobiles.hyp
Fichier2=Enquêtes\tourisme\tourisme.hyp
Fichier3=Enquêtes\hopital\hopital.hyp
Fichier4=Enquêtes\loto\loto.hyp
Couleurs=FF8080,602080,C0FFFF,E0E0A0,800060,8080FF,C08000,FFC0C0,800000,FF00FF,00FFFF,FFFF00,800080,000080,808000,FF0000,FFCC00,FFFFCC,CCFFCC,99FFFF,FFCC99,CC99FF,FF99CC,99CCFF,FF6633,CCCC33,00CC99,00CCFF,0099FF,0066FF,996666,969696,663300,669933,003300,003333,003399,663399,993333,333333,000000,FFFFFF,0000FF,00FF00,FF0000,00FFFF,FF00FF,FFFF00,000080,008000,800000,008080,800080,808000,C0C0C0,808080
[Configuration]
NombreDécimalesValeurs=2
NombreDécimalesPourcentages=1
SéparateurDécimales=,
SéparateurMilliers=1
NumérotationTitres=0
NumérotationVariables=1
LongeurVariables=255
LongeurWordBreak=255
LongeurMaximum=1000
PleinEcran=0
SéparateursMots=^t ^p ; " ' - = + , / ( ) { } [ ] < > . ? ¿ ! : ~ & # % ^^ § @ ~ – ` ’ » « …
SéparateursRéponses=^t^p;
ProcesseurCE=ARM
TypeVue=1
TypeFormulaire=3
NumérosModalités=0
PoliceTableur=Arial
TaillePoliceTableur=8
DoubleClicExplorateurVariables=-1
[Seuils]
FF=5
FF1=1
FF2=5
FF3=15
FF01=0.01
FF02=0.1
FF03=0.5
FF04=1
FF05=5
FF06=15
FF07=20
FN=5
FN1=1
FN2=5
FN3=15
FN01=0.01
FN02=0.1
FN03=0.5
FN04=1
FN05=5
FN06=15
FN07=20
NN=0.6
NN1=0.8
NN2=0.6
NN3=0.4
NN01=0.9
NN02=0.8
NN03=0.7
NN04=0.6
NN05=0.5
NN06=0.4
NN07=0.3
[Calculs]
Strict=0
CalculsStrictsEffectifMin=30
CalculsStrictsPourcentageInf5=20
PrincipauxElémentSignificatifs=0
PrincipauxElémentsEffectif=10
PrincipauxElémentsEcart=0
PrincipauxElémentsMax=3
[BarresOutils]
Application=1
Questionnaire=1
Insertion=1
Format=1
Relations=1
Image=0
Etat=1
Explorateur=1
TexteEtat=Base de données
TailleExplorateur=250
[Publication]
Utilisateur=
MotDePasse=
Destination=0
SOL=1;;
Répertoire=
FormScript=
CibleScript=0
Simplifiée=1
AccèsCompte=1
[Proxy]
Proxy=0
Hôte=
Port=21
Utilisateur=
MotDePasse=
[Serveur]
Hôte=DESKTOP-U1529DK
IP=
Port=80
Scripts=Etudes
Pages=Pages
Droits=
SMTP=
Navigation=0
DélaiCache=30
DélaiSauve=3
MaxPages=10
Debug=0
URLComptesASPX=
Sécurisé=0
[Mail]
From=
SMTP=
[Scanner]
Résolution=200
RectoVerso=0
AutoConfiguration=1
ImagesNumérisées=0
IgnorerMalRemplies=0
ArrêtSurErreur=1
SeuilBas=20
SeuilHaut=95
AutoRotation=1
AutoRotationActive=0
AutoCorrection=0
Modèle=0
OCR=1
SauverImages=0
RépertoireImages=
SauverPaquet=0
RépertoirePaquet=
Journal=1
Affichage=1
DernierID=128
[Caere]
SN=IOEULSJJFT
Répertoire=Eureka\Caere
SéparateursNumérique=,.
Trace=0
[Couleurs]
Couleur0=FFFFFF
Couleur1=FFFFFF
Couleur2=FFFFFF
Couleur3=FFFFFF
Couleur4=FFFFFF
Couleur5=FFFFFF
Couleur6=FFFFFF
Couleur7=FFFFFF
Couleur8=FFFFFF
Couleur9=FFFFFF
Couleur10=FFFFFF
Couleur11=FFFFFF
Couleur12=FFFFFF
Couleur13=FFFFFF
Couleur14=FFFFFF
Couleur15=FFFFFF
[MiseAuPoint]
Total100p100=0
MaxVariablesGroupe=255
DécompositionOption1=0
DécompositionOption2=0
PropriétésVersStyle=0
SigneFF=0
ImpressionRelationTestée=1
FormatXML=0
StylesXML=1
Office=1111110
IgnorerRéférences=0
TailleTable=10000
Log1Heure=0
DebugHTTP=0
SéparateurHTTP=<table><tr><td height="1"></td></tr></table>
TimeOutPublication=18000
TableauCaractéristiques=1
XGraph=0
Lissage=0
MultiLangue=1
Thème1=2
Thème2=11
"""
    fichier = open(pathparamsfile, "w")
    fichier.write(data)
    fichier.close()
    filecopyto(pathparamsfile,'c:/SphinxV5')
    remove_file(pathparamsfile)
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

December 5, 2017 - 4:52 PM

Good morning,
Since the file will contain non-ASCII characters, an "encoding" must be chosen.

There's a good chance that UTF8 will work...

So use the "codecs" module

Code: Select all

import tempfile
import codecs

def install():
    pathparamsfile = makepath(tempfile.gettempdir(),'Eureka.ini')
    data = ur"""[OEM]
[Langue]
Ressources=FR
Impression=FR

[Menus]
primo=1
Fichier=00010100011101
Edition=11111111000
Stade=01
...
SéparateurHTTP=<table><tr><td height="1"></td></tr></table>
TimeOutPublication=18000
TableauCaractéristiques=1
XGraph=0
Lissage=0
MultiLangue=1
Thème1=2
Thème2=11
"""
    fichier = codecs.open(pathparamsfile, "wb", encoding='utf8')
    fichier.write(data)
    fichier.close()
    filecopyto(pathparamsfile,'c:/SphinxV5')
    remove_file(pathparamsfile)

Tranquil IT
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

December 6, 2017 - 3:30 PM

Thank you, that seems to solve the problem.
However, copying the file overwrites the destination folder with the source file, without the extension! I don't understand, I've used this command before without any problems...

Code: Select all

filecopyto(pathparamsfile,'c:/SphinxV5')
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

December 6, 2017 - 3:45 PM

There is indeed an indeterminacy, is the destination a directory or the file.
Just to be sure...:

Code: Select all

filecopyto(pathparamsfile,'c:/SphinxV5/Eureka.ini')
Tranquil IT
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

December 6, 2017 - 4:25 PM

I'm now getting the following error: IOError: [Errno 2] No such file or directory: 'c:/SphinxV5/Eureka.ini'

I'm wondering if the script is copying the file before the installer creates it?!
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

December 6, 2017 - 4:41 PM

It's possible...
Some installers hand over control immediately after launch but continue running in the background (example: Adobe CS 6)

In this case, it is necessary to monitor the end of the installation by analyzing the processes in progress in a waiting loop.
In the case of the ini file, you can try waiting for the file to be created.

Example...

Code: Select all

from setuphelpers import *
import time

def install():
    # lancement de l'installeur..
    run('install_sphinx.exe /silent')

    # attente du fichier pendant au plus 2 minutes
    start_time = time.time()
    while not isfile('c:/SphinxV5/Eureka.ini') and time.time() - start_time < 2*60:
        time.sleep(2)

    if not isfile('c:/SphinxV5/Eureka.ini'):
        error('Fichier configuration non present')

    # fichier de configuration
    pathparamsfile = makepath(tempfile.gettempdir(),'Eureka.ini')
    data = ur"""[OEM]
[Langue]
Ressources=FR
Impression=FR

[Menus]
primo=1
Fichier=00010100011101
Edition=11111111000
Stade=01
...
SéparateurHTTP=<table><tr><td height="1"></td></tr></table>
TimeOutPublication=18000
TableauCaractéristiques=1
XGraph=0
Lissage=0
MultiLangue=1
Thème1=2
Thème2=11
"""
    fichier = codecs.open(pathparamsfile, "wb", encoding='utf8')
    fichier.write(data)
    fichier.close()
    filecopyto(pathparamsfile,'c:/SphinxV5')
    remove_file(pathparamsfile)
Tranquil IT
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

December 11, 2017 - 2:52 PM

Okay, your solution works!

Thank you!
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
Locked