Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da6c3da

Browse files
segevfinerserhiy-storchaka
authored andcommitted
bpo-32370: Use the correct encoding for ipconfig output in the uuid module. (GH-5608)
1 parent b7e2d67 commit da6c3da

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Lib/uuid.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def _netstat_getnode():
468468

469469
def _ipconfig_getnode():
470470
"""Get the hardware address on Windows by running ipconfig.exe."""
471-
import os, re
471+
import os, re, subprocess
472472
first_local_mac = None
473473
dirs = ['', r'c:\windows\system32', r'c:\winnt\system32']
474474
try:
@@ -480,11 +480,13 @@ def _ipconfig_getnode():
480480
pass
481481
for dir in dirs:
482482
try:
483-
pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all')
483+
proc = subprocess.Popen([os.path.join(dir, 'ipconfig'), '/all'],
484+
stdout=subprocess.PIPE,
485+
encoding="oem")
484486
except OSError:
485487
continue
486-
with pipe:
487-
for line in pipe:
488+
with proc:
489+
for line in proc.stdout:
488490
value = line.split(':')[-1].strip().lower()
489491
if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
490492
mac = int(value.replace('-', ''), 16)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use the correct encoding for ipconfig output in the uuid module.
2+
Patch by Segev Finer.

0 commit comments

Comments
 (0)