Search code examples
cherrypy

cherrypy: how to access file system from cherrypy?


I am working on a cherrpy web service to work with my web app. In this service it needs to be able to access the file system. For example, I want to be able to list all files under a certain directory. I am using os.walk('/public/') but don't seem to get it to work, even though the same code works outside of cherrpy.

Is there a way to make it work so I can use cherrypy to manage files?


Solution

  • What user is the webapp running as, and does it have access to read the folder?

    According to the documentation os.walk() will ignore errors from the underlying calls to os.listdirs()

    http://docs.python.org/release/2.4.4/lib/os-file-dir.html

    You could try setting the onerror argument like

    def print_error(error):
        print error
    
    os.walk('/public/', print_error)
    

    which might give you a hint as to what's going on.

    Also, you could try going directly to os.listdirs() and see if you get any errors from it.