title: "Permission Denied" From Python Server
body: <p>So basically, I'm a bit new to Python. I created a server and have it up and running just fine, have the files and everything showing up.</p>
  
  <p>But the problem is, every time I try to open a file, in Python, for reading/writing, my terminal throws an "access denied" error. </p>
  
  <p>You know, it's a basic server: </p>
  
  <pre><code>#!/usr/bin/env python
  import BaseHTTPServer
  import CGIHTTPServer
  import cgitb
  
  cgitb.enable();
  server = BaseHTTPServer.HTTPServer;
  handler = CGIHTTPServer.CGIHTTPRequestHandler;
  address = ("",80);
  handler.cgi_directories = ["/home"];
  
  httpd = server(address,handler);
  print("Working . . . ");
  httpd.serve_forever();
  </code></pre>
  
  <p>Nothing too fancy. So I start the server up, and then when the user navigates to the page, "/home/file.py" that contains the code:</p>
  
  <pre><code>#!/usr/bin/env python
  f = open("asdf.txt","w");
  </code></pre>
  
  <p>Nothing at all happens, and when I check the terminal that's running the server, it says,</p>
  
  <pre><code> localhost - - [27/Aug/2012 17:58:18] "GET /home/file.py HTTP/1.1" 200 -
   Traceback (most recent call last):
     File "/home/SERVER/home/file.py", line 4, in &lt;module&gt;
       f = open("asdf.txt","w");
   IOError: [Errno 13] Permission denied: 'asdf.txt'
  </code></pre>
  
  <p>I've been looking up this for awhile now, but I've yet to find a solution. It's probably a very simple solution that would make professional Python users facepalm, but take into account that all self-taught programmers have to start somewhere. And for me, I'm a bit at the bottom right now, in Python terms at least. </p>
  
  <p>I have tried a couple solutions I've found from the internet (and from the "Questions that may already have your answer"), like importing "os" and using that to specify the exact location to create file. I've tried using "sudo chmod g+w" on the SERVER folder and the folder that contains the Python scripts. But none of these interwebs solutions are helping me. </p>
  
  <p>I'll also remember to accept the answer. </p>
  
  <p>I tried to make the question as precise as I could. So if there's anything else you'd need to know, I can just update it.</p>
  
  <p>Since it's a "permission denied" error, I'm doubting it's Python's fault, and probably some permissions I didn't setup somewhere. But I don't know which or where they'd be. </p>