简体   繁体   English

Python、linux:使用wifi Cell和Scheme,如何连接到网络?

[英]Python, linux: Using wifi Cell and Scheme, how do I connect to a network?

For reference: https://wifi.readthedocs.io/en/latest/scanning.html#connecting-to-a-network供参考: https://wifi.readthedocs.io/en/latest/scanning.html#connecting-to-a-network

I have been successful in getting a list of wireless networks, by executing the following commands:通过执行以下命令,我已成功获取无线网络列表:

from wifi import Cell, Scheme
cells = list(Cell.all('wlan0'))
my_wifi_cell = cells[some_index]

But when I try to use it (as in the example above):但是当我尝试使用它时(如上例所示):

scheme = Scheme.for_cell('wlan0', 'home', my_wifi_cell, 'my password')
scheme.save()
scheme.activate()

While running python elevated, scheme.activate() fails with the following traceback:在运行 python 提升时,scheme.activate() 失败并出现以下回溯:

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python3.7/dist-packages/wifi/scheme.py", line 172, in activate
   subprocess.check_output(['sbin/ifdown', self.interface], stderr=subprocess.STDOUT)
 File "/usr/lib/python3.7/subprocess.py", line 395, in check_output
   **kwargs).stdout
 File "/usr/lib/python3.7/subprocess.py", line 487, in run
   output=stdout, stderr=stderr)
subprocess.CalledProcessError: command '['/sbin/ifdown', 'wlan0']' returned non-zero exit status 1.

Sorry if there are any mistakes, I had to manually type that over.对不起,如果有任何错误,我不得不手动输入。 Anyway, I verified that the ssid and passkey were correct, I'm just not sure how to resolve this error.无论如何,我验证了 ssid 和密码是正确的,我只是不确定如何解决这个错误。 Any thoughts?有什么想法吗?

Update: According to https://github.com/rockymeza/wifi/issues it looks like this just doesn't work anymore(?) Is there a fix for this, or should I just start looking somewhere else?更新:根据https://github.com/rockymeza/wifi/issues看来这不再起作用了(?)有解决办法,还是我应该开始寻找其他地方?

I believe what you are missing is root privilege.我相信您缺少的是root权限。 Let try to run it with root让我们尝试用 root 运行它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何使用 python 连接到 WIFI.network 3 - how can i connect to WIFI network using python 3 如何使用 Python 3 在 Windows 上连接到 WiFi 网络? - How to connect to WiFi network on Windows using Python 3? 我尝试通过 python 上的一个脚本在 ubuntu 中连接网络 wifi - I try connect a network wifi in ubuntu through one script on python 在尝试使用python连接到wifi网络时出现ConnectionError - Getting ConnectionError, while trying to connect to wifi network using python 如何在python中连接/断开/配置无线网络? - How do I connect/disconnect/configure a wireless network in python? 使用python连接到wifi网络 - Connecting to a wifi network using python 如何使用 python 代码将 windows.network 驱动器连接到 Azure Function 具有 Linux 环境的应用程序 - How to connect windows network drive using python code to Azure Function App which is having Linux environment 如果您之前没有连接到 wifi,如何通过 linux 或 Windows 上的 python 连接到 wifi。 (输入:SSID、密码) - How to connect to wifi if you didnt connect to it before, by python on linux or Windows. (input: SSID, PASSWORD) 如何在Linux中使用python更改wifi接口的IP地址? - How to change IP address of wifi interface using python in linux? 如何使用python查找并连接所有可用的wifi信号? - How to find all and connect all available wifi signals using python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM