title: windows - PermissionError: [Errno 13] Permission denied when accessing Apache log file
body: <p>Here is my code, which intends to constantly check apache log file and process the newly updated contents.</p>
  
  <pre><code># detect.py
  fp = open(r'C:\xampp\apache\logs\access.log', 'r')
  ... 
  def follow(fp):
      fp.seek(0, 2)
      while True:
          line = fp.readline()
          if not line:
              time.sleep(0.0001)
              continue
          yield line
  ...
  if __name__ == '__main__':
      loglines = follow(fp)
      for line in loglines:
          data = LogParser(line, db)
          ...
  </code></pre>
  
  <p>When I run this file, I always get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File ".\core\detect.py", line 28, in &lt;module&gt;
      for line in loglines:
    File ".\core\detect.py", line 19, in follow
      line = fp.readline()
  PermissionError: [Errno 13] Permission denied
  </code></pre>
  
  <p>I have tried nearly all available means, such as: changing file privileges, running as administrators, killing all python related process before running this file ...
  but I still get that error. I want to know how to deal with this problem.</p>