Hi,
When i run your script with Python 3 i get a UnicodeDecodeError:
Traceback (most recent call last):
File "D:\Downloads\getmac.py", line 42, in <module>
win = MainFrame()
File "D:\Downloads\getmac.py", line 10, in __init__
adapters = self.GetAdapters()
File "D:\Downloads\getmac.py", line 31, in GetAdapters
infos = line.decode('utf-8').split('","')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x84 in
position 17: invalid start byte
O.K. after changing my network name I see this too.
So, no idea what stdout uses as encoding, tried a few others such as
"ISO-8859-1", "cp1252" but no luck.
Doing a bit of googling I came across:
http://bugs.python.org/issue6135
But can't find if this has been resolved/introduced in Py3.4.
Under Windows, you need to decode subprocess input and output with the
console input and output encodings. The only way to reliably get that
(which I know of) is to use Python for Windows extensions (pywin32). E.g.:
import subprocess
from encodings.aliases import aliases
from win32console import GetConsoleOutputCP
# Get console output encoding
enc = aliases.get(str(GetConsoleOutputCP()))
p = subprocess.Popen(r'getmac /V /FO CSV',
stdout=sp.PIPE, stderr=sp.PIPE)
stdout, stderr = [v.decode(enc) for v in p.communicate()]
(shell=True is only necessary for shell commands by the way, e.g. things
like 'dir' etc.)
This works under Python 2.x and 3.x.
If you're using Python 2.x, one caveat applies if you localize your
application (i.e. if you use locale.setlocale and derivatives):
In that case, the encoding of stdio changes, and you need to use the
encoding specific to the locale being used, i.e. locale.getlocale()[1].
···
Am 17.07.2014 13:11, schrieb Werner:
--
Florian Höch