[Python] Reading files with python and open()

618 views
Skip to first unread message

warlock24

unread,
Nov 7, 2009, 10:39:03 AM11/7/09
to Google App Engine
Hello

Could someone tell me why tis code does't work?

[CODE]
ROOT_DIR = os.path.dirname(__file__)
pageUrl = os.path.join(ROOT_DIR, 'pages/' + pageName + '.html')
pageContent = open(pageUrl, 'r').read()
[/CODE]

i get error message

[CODE]
IOError: [Errno 2] No such file or directory: '/base/data/home/apps/
warlock24/1.337586579904043005/pages/home.html'
[/CODE]

where are my files? :(

Gabriel Robertson

unread,
Nov 7, 2009, 8:29:10 PM11/7/09
to google-a...@googlegroups.com

I would think that would work, but I cook everything in myself; you
might just try using a relative directory access instead of absolute,
I have heard that works best in GAE.

warlock24

unread,
Nov 8, 2009, 5:20:41 AM11/8/09
to Google App Engine
I found my file :D

but got another problem :/

pageContent = open(pageUrl, 'r').read()
IOError: [Errno 13] Permission denied: '/pages/home.html'

how do i set file permissions? Something i must do in YAML file?

Rodrigo Moraes

unread,
Nov 9, 2009, 3:27:44 AM11/9/09
to google-a...@googlegroups.com
On Sat, Nov 7, 2009 at 1:39 PM, warlock24 <warl...@gmail.com> wrote:
> [CODE]
> ROOT_DIR = os.path.dirname(__file__)
> pageUrl = os.path.join(ROOT_DIR, 'pages/' + pageName + '.html')
> pageContent = open(pageUrl, 'r').read()
> [/CODE]

Is the .html file mapped in app.yaml as static file? If it is, it
can't be read directly. If not, try using abspath:

ROOT_DIR = os.path.abspath(os.path.dirname(__file__))

-- rodrigo

Wooble

unread,
Nov 9, 2009, 9:06:19 AM11/9/09
to Google App Engine
You didn't find your file. You're trying to read /pages at the root
of the filesystem, and you don't have permission to read anything
above your application directory. The error isn't telling you that
you don't have permission to read it, it's that you don't even have
permission to check for its existence.

风笑雪

unread,
Nov 9, 2009, 9:26:10 AM11/9/09
to google-a...@googlegroups.com
Hi, please make sure the pages dir is NOT a static dir.

Static files are in different place with your script files, they can't
be accessed by your script.

2009/11/9 Wooble <geoff...@gmail.com>:

Gezim Hoxha

unread,
Nov 9, 2009, 10:17:12 PM11/9/09
to google-a...@googlegroups.com
On Mon, Nov 9, 2009 at 7:06 AM, Wooble <geoff...@gmail.com> wrote:

You didn't find your file.  You're trying to read /pages at the root
of the filesystem, and you don't have permission to read anything
above your application directory.  The error isn't telling you that
you don't have permission to read it, it's that you don't even have
permission to check for its existence.


Why then would he be getting this error in the other scenario with an absolute URL:
"IOError: [Errno 2] No such file or directory: '/base/data/home/apps/"


Gezim Hoxha (aka Gizmo)
http://www.gizmobooks.com -- buy/sell your textbooks

Wooble

unread,
Nov 10, 2009, 10:36:07 AM11/10/09
to Google App Engine
That's not a permissions error; that one is where he's trying to read
from his application directory (which is allowed), but the file's not
there. Almost certainly it's specified as a static file in app.yaml;
these are not copied to the application directory but are served from
different servers.

On Nov 9, 10:17 pm, Gezim Hoxha <hge...@gmail.com> wrote:
> On Mon, Nov 9, 2009 at 7:06 AM, Wooble <geoffsp...@gmail.com> wrote:
>
> > You didn't find your file.  You're trying to read /pages at the root
> > of the filesystem, and you don't have permission to read anything
> > above your application directory.  The error isn't telling you that
> > you don't have permission to read it, it's that you don't even have
> > permission to check for its existence.
>
> Why then would he be getting this error in the other scenario with an
> absolute URL:
> "IOError: [Errno 2] No such file or directory: '/base/data/home/apps/"
>
> Gezim Hoxha (aka Gizmo)http://www.gizmobooks.com-- buy/sell your textbooks
Reply all
Reply to author
Forward
0 new messages