IOError: [Errno 1] 操作不允许

3

我正在使用Eclipse在Ubuntu上编写Python 2.7.3代码。我是Python和Linux的初学者,同时也在使用模块pythonwifi 0.3.1。该代码将扫描frequency_channel_map中的频率,wifi.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,但没有找到我能理解的东西。

附注:这是在stackoverflow上的第一篇帖子,请给予建设性的意见。

1个回答

3

通常错误;操作不允许,如果您不是root用户,则会发生这种情况, 即,请确保以root用户身份运行此python脚本, 要做到这一点。 打开您的Linux终端, 并键入sudo su。 您将获得提示要求输入密码,此密码与您用于登录Linux的密码相同。 然后运行您的Python代码。


有相同的问题,以root身份运行在Ubuntu上也无法解决这个问题。 - dm76

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接