scheme.activate 返回状态 1 [英] scheme.activate returns status1

查看:75
本文介绍了scheme.activate 返回状态 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从用户那里获取 SSID 和密码并将其连接到 WIFI.为此,我正在使用 Raspbian 和 Python3.

I want to get the SSID and Password from the user und connect it to WIFI. I'm using Raspbian and Python3 for that.

我的代码:

#!/user/bin/python3.5
#!/user/bin/env python

from wifi import Cell, Scheme

def WirelessConnection():
userSSID = input("Enter the SSID: ")
userPass = input("Enter the Password: ")

cells = Cell.all('wlan0')
schemes = list(Scheme.all())
for cell in cells:
if cell.ssid == userSSID:
print('Connecting to %s' % userSSID)
passKey = userPass
scheme = Scheme.for_cell('wlan0', 'netcom3', cell, passKey)
scheme.activate()
else:
print('WRONG!')

WirelessConnection()

问题是scheme.activate"行...我会得到一个错误:

The problem is the "scheme.activiate" line... I'll get an error:

回溯(最近一次调用最后一次):文件/home/pi/Desktop/idk.py",第 30 行,在 WirelessConnection() 文件中/home/pi/Desktop/idk.py",第 26 行,在 WirelessConnectionscheme.activate() 文件/usr/local/lib/python3.5/dist-packages/wifi/scheme.py",第 174 行,在activate subprocess.check_output(['/sbin/ifdown', self.interface],stderr=subprocess.STDOUT) 文件/usr/lib/python3.5/subprocess.py",第 316 行,在 check_output 中**kwargs).stdout File "/usr/lib/python3.5/subprocess.py", line 398, in run output=stdout, stderr=stderr) subprocess.CalledProcessError:命令 '['/sbin/ifdown', 'wlan0']' 返回非零退出状态 1

Traceback (most recent call last): File "/home/pi/Desktop/idk.py", line 30, in WirelessConnection() File "/home/pi/Desktop/idk.py", line 26, in WirelessConnection scheme.activate() File "/usr/local/lib/python3.5/dist-packages/wifi/scheme.py", line 174, in activate subprocess.check_output(['/sbin/ifdown', self.interface], stderr=subprocess.STDOUT) File "/usr/lib/python3.5/subprocess.py", line 316, in check_output **kwargs).stdout File "/usr/lib/python3.5/subprocess.py", line 398, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['/sbin/ifdown', 'wlan0']' returned non-zero exit status 1

我在 scheme.py 中更改了这一行:

I changed this line in scheme.py:

['/sbin/ifdown', 'wlan0']

到:

['/sbin/ifconfig', 'wlan0', 'down']

在这行之后我添加了一个sleep(30)".

After this line I added a "sleep(30)".

我将接口配置更改为:

auto wlan0
iface wlan0 inet loopback 

还有很多其他事情......但我仍然收到这个错误.是什么原因?我能做什么?

and lot of another thing... But I'm still getting this error. What is the reason? What can I do?

推荐答案

我遇到了同样的问题.看来您需要以超级用户身份执行.我在scheme.py中更改了这一行:

I had the same problem. It seems that u need to execute as super user. I changed in the scheme.py this line:

    subprocess.check_output(['/sbin/ifdown', self.interface], stderr=subprocess.STDOUT)

通过这一行

subprocess.check_output(['sudo','/sbin/ifconfig', self.interface,'up'], stderr=subprocess.STDOUT)

希望对你有用

这篇关于scheme.activate 返回状态 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆