这是我的一段python代码。你知道吗
import os
print 'netsh interface ip set address name="' + adapter + '" static '+ staticaddr +' 255.255.255.0 192.168.1.1'
直到这一点都是好的适配器包括在我的驱动程序。你知道吗
现在当我以管理员的身份运行这个程序时
os.system('netsh interface ipv4 set address name="' + adapter + '" static '+ staticaddr +' 255.255.255.0 192.168.1.1')
它触发此错误:
La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte.
这意味着命令的语法不正确。你知道吗
我试过os.system('netsh interface ipv4 set address name="' + adapter.encode('ascii','ignore') + '" static '+ staticaddr +' 255.255.255.0 192.168.1.1')
现在出现这种异常:
'ascii' codec can't decode byte 0x82 in position 11: ordinal not in range(128)
问题到底出在哪里?你知道吗
我的网络适配器的名称是:Connexion réseau sans fil
adapter.encode('ascii','ignore')
引发UnicodeDecodeError
,因为adapter
是一个非ascii字符串。要对它进行编码(即从unicode转换为str),Python首先尝试对它进行解码(即从str转换为unicode),但失败了(adapter
是非ascii)。你知道吗完全切换到unicode:
相关问题 更多 >
编程相关推荐