Re: [google-appengine] Get file size with Python

260 views
Skip to first unread message

Takashi Matsuo

unread,
Sep 30, 2012, 10:04:07 PM9/30/12
to google-a...@googlegroups.com

Hi Phát,

Can you show us the actual code and the error message please :)

-- Takashi


On Sat, Sep 29, 2012 at 7:05 PM, Phát Trần <phat...@gmail.com> wrote:
I try to get file size with os.path("asd.txt")
But I cann't. Don't know why. Any help?

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/I7dx2D_ZNbYJ.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.



--
Takashi Matsuo | Developers Advocate | tma...@google.com

GregF

unread,
Sep 30, 2012, 11:32:13 PM9/30/12
to google-a...@googlegroups.com
Appengine does not give you access to the filesystem. You will need to use either the datastore or the blobstore to store local information.

Cheers!
Greg.

Gopal Patel

unread,
Sep 30, 2012, 11:58:09 PM9/30/12
to google-a...@googlegroups.com
It prohibits "writing". It allows reading anyway you want.

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/Q1UPQlf3YBsJ.

Phát Trần

unread,
Oct 1, 2012, 12:39:55 AM10/1/12
to google-a...@googlegroups.com
So use we use read file. And how can we know its size

Vào 10:58:48 UTC+7 Thứ hai, ngày 01 tháng mười năm 2012, gops đã viết:

Takashi Matsuo

unread,
Oct 1, 2012, 1:02:36 AM10/1/12
to google-a...@googlegroups.com
import os
size = os.stat(filename).st_size
# or
size = os.path.getsize(filename)

Does one of these work for you?


To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/l__keJOGOxkJ.

To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

Phát Trần

unread,
Oct 1, 2012, 1:41:41 AM10/1/12
to google-a...@googlegroups.com
I tried but it's not work.

Vào 12:02:56 UTC+7 Thứ hai, ngày 01 tháng mười năm 2012, Takashi Matsuo (Google) đã viết:

Geoffrey Spear

unread,
Oct 1, 2012, 7:48:37 AM10/1/12
to google-a...@googlegroups.com
What does "does not work" mean? Where's the code you're running? Where's the output, or the traceback?

Phát Trần

unread,
Oct 1, 2012, 8:20:50 AM10/1/12
to google-a...@googlegroups.com
I use 
import os
print(os.path.getsize("abc.txt"))
Ane I got the log:

WARNING  2012-10-01 12:16:13,943 dev_appserver_import_hook.py:595] Blocking access to static file ".....\abc.txt"
ERROR    2012-10-01 12:16:13,944 wsgi.py:203] 
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 195, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in _LoadHandler
    handler = __import__(path[0])
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 719, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 1923, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 719, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 1787, in FindAndLoadModule
    description)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 719, in Decorate
    return func(self, *args, **kwargs)
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 1730, in LoadModuleRestricted
    description)
  File "D:\vangvn-igold\size.py", line 18, in <module>
    print(os.path.getsize("abc.txt"))
  File "C:\Python27\lib\genericpath.py", line 49, in getsize
    return os.stat(filename).st_size
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 663, in __call__
    raise OSError(errno.EACCES, 'path not accessible', path)
OSError: [Errno 13] path not accessible: 'abc.txt'

Geoffrey Spear

unread,
Oct 1, 2012, 8:39:31 AM10/1/12
to google-a...@googlegroups.com
Your file is specified in app.yaml as a static file; these files are not accessible by the application; they're uploaded to a completely different place from your application code, and are meant to only be served directly to your users' browsers, not accessed in your code. dev_appserver blocks access to them to mimic what you'd see on the production server.

If this file is not meant to ever be served directly to users, change app.yaml so it's no longer static. If you need to both serve it to users and access it in program code, you'll need 2 copies of it (or a symbolic link to it, although I'm not sure how this works on Windows), one of which is static and one of which isn't, probably in different directories.
Reply all
Reply to author
Forward
0 new messages