1
votes

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

1 Answers

1
votes

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