我正在尝试从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'