Page 1 of 1

Accented characters

Published: April 7, 2015 - 11:54 AM
by Cadou
Good morning,

I am currently creating a WAPT package to use a WSUS server in an environment without AD.
I'm not proficient in Python, and despite my research, I can't seem to preserve the character "é" in a string. I've tried several solutions, such as using "u" before it, without success.

Here is the relevant code snippet (the character is located in "unassigned computer"):

Code: Select all

#ouverture de la clef  keygroupe=reg_openkey_noredir(HKEY_CURRENT_USER,'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\WindowsUpdate\\AU',sam=KEY_WRITE,create_if_missing=True)

#determine le groupe d'attribution de l'ordinateur
keyname=reg_openkey_noredir(HKEY_LOCAL_MACHINE,'SYSTEM\\ControlSet001\\Control\\ComputerName\\ComputerName',sam = KEY_READ)

localhost = reg_getvalue(keyname,'ComputerName')

    if type(localhost[1:4]) == int:
        groupe = 'Pedagogique'
    else:
	groupe = 'Ordinateur non attribué' 

#indique le groupe d'attribution au serveur WSUS
reg_setvalue(keygroupe,'TargetGroupEnabled',1,REG_DWORD)
reg_setvalue(keygroupe,'TargetGroup',groupe,REG_SZ)
print('Ordinateur attribue au groupe ' + '"' + groupe + '"')
This "Unassigned Computer" group is a default group that I cannot delete or modify; I would prefer to use it.
Do you have a solution to properly account for this characteristic?

Thank you so much.

Antoine Cadou

Re: Accented characters

Published: April 8, 2015 - 2:37 PM
by Yvan Karmouta
Hello,
did you specify the encoding at the beginning of the setup.py file:
# -*- coding: utf-8 -*-

Re: Accented characters

Published: April 8, 2015 - 4:29 PM
by Cadou
Thank you for your reply.

The setup.py file does indeed begin with the line:
# -*- coding: utf-8 -*-

Please let me know if anything else can be checked.

Re: Accented characters

Published: April 9, 2015 - 9:31 AM
by Yvan Karmouta
Okay, one second simple thing, but in the code you copied, the indentation for the line in question is missing. Did you add it to your file?

Re: Accented characters

Published: April 9, 2015 - 1:53 PM
by Cadou
Indeed, the indentation was not respected in my post.
But it seems suitable in my file.
Here is the beginning of the code:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

# registry key(s) where WAPT will find how to remove the application(s)
uninstallkey = []

# command(s) to launch to remove the application(s)
uninstallstring = []

# list of required parameters names (string) which can be used during install
required_params = []


def install():
    # if you want to modify the keys depending on environment (win32/win64... params..)
    global uninstallkey
    global uninstallstring

    print('installing tis-clientwsus')
I found a way to work around the problem by using 'unassigned computers' instead of 'unassigned computers'.
However, I remain interested if you have an answer.

Re: Accented characters

Published: April 14, 2015 - 10:55 AM
by ssamson
Hello,

are you sure you have these properties in your file?

Re: Accented characters

Published: April 14, 2015 - 3:19 PM
by Cadou
Hello,

After checking, the file properties are UTF-8 no BOM.
I tried with UTF-8 (without BOM) and the result is the same:
when I print('Unassigned computers') I get Unassigned computers,s

Re: Accented characters

Published: April 21, 2015 - 12:03 PM
by htouvet
The setup.py file must be encoded in UTF-8 without BOM.
You must put # -*- coding: utf-8 -*- at the beginning of the file
and prefix the strings with a 'u' for Unicode.
print(u'Computer assigned to the group')

Re: Accented characters

Published: April 27, 2015 - 1:30 PM
by Cadou
Hello,
thank you for your reply.
Unfortunately, I have the same problem despite using the "u" prefix and the other parameters you gave me.