0

我正在尝试从 python 脚本中读取 Apache 访问日志文件并实时提取 IP 地址。我正在使用 python CGI 编程。我已授予 777 权限。

-rwxrwxr-x 1 root adm 1012822 Jun  5 13:02 /var/log/apache2/access.log

这是我正在使用的代码

for line in open('/var/log/apache2/access.log'):
    ip = line.split(' ')[0]
    print ip

但显示以下错误。这里有什么问题?

 A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
     /usr/lib/cgi-bin/log.py in ()
          6 form = cgi.FieldStorage()
          7 
    =>    8 for line in open('/var/log/apache2/access.log'):
          9     ip = line.split(' ')[0]
         10     print ip
    line undefined, builtin open = <built-in function open>

    <type 'exceptions.IOError'>: [Errno 13] Permission denied: '/var/log/apache2/access.log'
          args = (13, 'Permission denied')
          errno = 13
          filename = '/var/log/apache2/access.log'
          message = ''
          strerror = 'Permission denied' 
4

0 回答 0