scheme.activate returns status1

試著忘記壹切 提交于 2021-01-29 08:11:35

问题


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

My Code:

#!/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()

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

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

I changed this line in scheme.py:

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

to:

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

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

I changed the interfaces-config to:

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?


回答1:


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)

by this line

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

Hope it works for you



来源:https://stackoverflow.com/questions/53522390/scheme-activate-returns-status1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!