Page 1 of 1

Accent problem

Published: Dec 14, 2017 - 09:51
by steph.prevot
Hello,
I'm having trouble with the "é" when trying to switch my Windows 7 PCs from static IPs to DHCP. My batch file runs fine manually, but I'm having an encoding issue with WAPT. So I tried replacing utf-8 with cp850:

# -*- coding: cp850 -*-
from setuphelpers import *

uninstallkey = []

def install():
print("Updating IP interfaces")
run (r'reg import DHCP-CLIENT.reg')
run (u'netsh interface ip set dns "Local network connection" dhcp')
run (u'netsh interface ip set address "Local network connection" dhcp')

but I'm back to my encoding problem with the message:
Updating IP interfaces
'ascii' codec can't encode characters in position 42-44: ordinal not in range(128) : faulty string is 'u'netsh interface ip set dns "Connection "on local network" dhcp

Thank you for your help

Re: Accent problem

Published: Dec 14, 2017 - 5:40 PM
by dcardon
You should avoid accented characters in run commands as much as possible. Input and output encoding are never truly controlled (this isn't a WAPT problem per se, it's a cmd.exe issue).

It's better to use wmi commands, which are usable in Python, something like this: `

import wmi
nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True)
for nic in nic_configs:
nic.EnableDHCP()`

And don't forget to check in the package that there's a lease available for your machine before switching over!

Re: Accent problem

Published: Dec 15, 2017 - 12:50
by steph.prevot
Hi,

thanks for the help.
WMI is way beyond my skill level, so I made a little script that runs at login and does the job perfectly.

Cheers!