3

我在运行 ubuntu 的 Python 2.7.3 中使用 Eclipse 编写我的第一个代码 该代码应扫描频率,frequency_channel_mapwifi.scan()应检索具有 for 循环中列出的信息的对象

#!/usr/bin/python2

from pythonwifi.iwlibs import Wireless

frequency_channel_map = {
    2412000000: "1",
    2417000000: "2",
    2422000000: "3",
    2427000000: "4",
    2432000000: "5",
    2437000000: "6",
    2442000000: "7",
    2447000000: "8",
    2452000000: "9",
    2457000000: "10",
    2462000000: "11",
    2467000000: "12",
    2472000000: "13",
    2484000000: "14",
    }

wifi = Wireless("wlan")

for ap in wifi.scan():
    print "SSID: " + ap.essid
    print "AP: "+ ap.bssid
    print "Signal: " + str(ap.quality.getsignallevel())
    print "Frequ: "+ str(ap.frequency.getfrequency())
    print "Chanel :"+ frequency_channel_map.get(ap.frequency.getfrequency())
    print "____"  

并得到那个问题

    Traceback (most recent call last):
  File "/home/andreas/workspace/test/firstModule.py", line 22, in <module>
    print wifi.commit()
  File "/usr/local/lib/python2.7/dist-packages/pythonwifi.egg/pythonwifi/iwlibs.py", line 679, in commit
    pythonwifi.flags.SIOCSIWCOMMIT)
  File "/usr/local/lib/python2.7/dist-packages/pythonwifi.egg/pythonwifi/iwlibs.py", line 1028, in iw_set_ext
    return self.iw_get_ext(ifname, operation, data)
  File "/usr/local/lib/python2.7/dist-packages/pythonwifi.egg/pythonwifi/iwlibs.py", line 1023, in iw_get_ext
    result = self._fcntl(request, ifreq)
  File "/usr/local/lib/python2.7/dist-packages/pythonwifi.egg/pythonwifi/iwlibs.py", line 1010, in _fcntl
    return fcntl.ioctl(self.sockfd.fileno(), request, args)
IOError: [Errno 1] Operation not permitted

我不知道为什么会发生。从 2 天开始搜索,IOError: [Errno 1] Operation not permitted但找到了我理解的任何内容

PS。关于stackoverflow的第一篇文章,请有见地

4

1 回答 1

3

通常错误;不允许操作,如果您不在 root 中,即确保您以 root 用户身份运行此 python 脚本来执行此操作,则会发生。打开你的 linux 终端,然后输入 sudo su。您将收到询问密码的提示,此密码与您登录 linux 时使用的密码相同。然后运行你的python代码。

于 2013-09-08T07:10:46.063 回答