我正在使用Python正则表达式来显示连接到计算机的所有互联网无线配置文件。在我的倒数第二行中出现错误(TypeError: cannot use a string pattern on a bytes-like object)
,请帮忙识别我的错误。谢谢。
我的程序
import subprocess,re
command = "netsh wlan show profile"
output = subprocess.check_output(command, shell=True)
network_names = re.search("(Profile\s*:\s)(.*)", output)
print(network_names.group(0))
错误
line 8, in <module>
return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object
output = output.decode()
?subprocess
返回的是bytes
类型,你需要手动转换为string
/unicode
(使用默认的'utf-8'
编码或其他编码 - 例如decode('latin1')
- 如果系统使用不同于utf-8
的编码)。 - furas