2017-07-12 68 views
0

欢迎我在Ubuntu 16.04上通过wifi连接设备时出现问题。我发现如果有人解释如何做到这一点页:Python在Ubuntu上通过wifi连接到设备

在终端: https://wifi.readthedocs.io/en/latest/wifi_command.html#tutorial

我已经像笔者秀一步走一步

$ PIP安装无线

sudo wifi scan

#wifi connect --ad-hoc essid

之后我写了密码。

但是,当我这样做,我得到了这样的一个错误:在

文件 “在/ usr/local/bin目录/ WIFI”,行202:

回溯(最近通话最后一个) args.func(参数)

文件 “的/ usr/local/bin中/ WIFI”,线90,在connect_command scheme.activate()

文件“/home/krzysztof/.local/lib/python2 .7/site-packages/wifi/scheme.py“,第172行,激活

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

文件 “/usr/lib/python2.7/subprocess.py”,线路574,在check_output 加注CalledProcessError(RETCODE,CMD,输出=输出)

subprocess.CalledProcessError:命令' ['/ sbin/ifdown','wlan0']' 返回的非零退出状态1

我确信我写的密码是正确的。

我以

$ WIFI_CLI_NAME =冷的wifi PIP安装无线

,但效果是一样使它第二种方式。

回答

0

我发现在Github上两个例子代码:

import wifi 


def Search(): 
    wifilist = [] 

    cells = wifi.Cell.all('wlan0') 

    for cell in cells: 
     wifilist.append(cell) 

    return wifilist 


def FindFromSearchList(ssid): 
    wifilist = Search() 

    for cell in wifilist: 
     if cell.ssid == ssid: 
      return cell 

    return False 


def FindFromSavedList(ssid): 
    cell = wifi.Scheme.find('wlan0', ssid) 

    if cell: 
     return cell 

    return False 


def Connect(ssid, password): 
    cell = FindFromSearchList(ssid) 

    if cell: 
     savedcell = FindFromSavedList(cell.ssid) 

     # Already Saved from Setting 
     if savedcell: 
      savedcell.activate() 
      return cell 

     # First time to conenct 
     else: 
      if cell.encrypted: 
       if password: 
        scheme = Add(cell, password) 

        try: 
         scheme.activate() 

        # Wrong Password 
        except wifi.exceptions.ConnectionError: 
         Delete(ssid) 
         return False 

        return cell 
       else: 
        return False 
      else: 
       scheme = Add(cell) 

       try: 
        scheme.activate() 
       except wifi.exceptions.ConnectionError: 
        Delete(ssid) 
        return False 

       return cell 

    return False 


def Add(cell, password=None): 
    if not cell: 
     return False 

    scheme = wifi.Scheme.for_cell('wlan0', cell.ssid, cell, password) 
    scheme.save() 
    return scheme 


def Delete(ssid): 
    if not ssid: 
     return False 

    cell = FindFromSavedList(ssid) 

    if cell: 
     cell.delete() 
     return True 

    return False 


if __name__ == '__main__': 
    # Search WiFi and return WiFi list 
    print Search() 

    # Connect WiFi with password & without password 
    print Connect('OpenWiFi') 
    print Connect('ClosedWiFi', 'password') 

    # Delete WiFi from auto connect list 
    print Delete('DeleteWiFi') 

enter code here 

但是在编译过程中我有错误:

我保存这个文件来polacz.py,之后我做了须藤使用chmod + X polacz的.py

和./polacz.py

./polacz.py:linia 6:语法由不可预料的标记错误(”

./polacz.py:linia 6:`def Search():'