2017-07-12 139 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():'