无法在 Windows 上使用 Python 连接到 Wifi 网络

时间:2021-02-24 13:23:49

标签: python windows

您好,我正在尝试使用 Python 连接到我的 Wifi 网络,但我无法连接 当我执行此代码时。

import winwifi
winwifi.WinWiFi.connect('ssid_of_the_router')

它显示我错误

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1370, in _readerthread
    buffer.append(fh.read())
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 2121: invalid start byte
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    winwifi.WinWiFi.connect("1234")
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\winwifi\main.py", line 188, in connect
    aps: List['WiFiAp'] = cls.scan()
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\winwifi\main.py", line 162, in scan
    cp: subprocess.CompletedProcess = cls.netsh(['wlan', 'show', 'networks', 'mode=bssid'])
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\winwifi\main.py", line 98, in netsh
    return subprocess.run(
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 495, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1028, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1420, in _communicate
    stdout = stdout[0]
IndexError: list index out of range

当我执行这个

winwifi.WinWiFi.connect("ssid_of_the_router","password")

然后什么都没发生 谁能告诉我我该怎么做????

0 个答案:

没有答案