Search code examples
pythongoogle-app-engineumask

Why does google app engine tell me that umask is not implemented in python on windows?


Does google app engine not support umask? I can use it in anaconda on windows, but when I try it in google app engine (running locally), it doesn't work.

This code:

import webapp2
import os

class MainHandler(webapp2.RequestHandler):
    def get(self):
        mask = os.umask(0o177)
        self.response.write(mask)

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

Gives me the following errors:

Traceback (most recent call last):

File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)

File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)

File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)

File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
return handler.dispatch()

File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)

File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)

File "C:\Users\Dan\Documents\Apps\test\main.py", line 22, in get
mask = os.umask(0o177)

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\python\stubs.py", line 40, in os_error_not_implemented
raise OSError(errno.ENOSYS, 'Function not implemented')

OSError: [Errno 40] Function not implemented

Solution

  • dev_appserver (the program you use to "run locally" a GAE app) does its best to reproduce the limitations you will encounter on the "sandbox" when you deploy and run in production (i.e on appspot.com) -- it IS, after all, a development tool intended to make it easier for you to code and debug applications to deploy to appspot.com.

    dev_appserver doesn't do a perfect job of this emulation, but it does a pretty good one -- in particular, forbidding your app from using standard library modules that are not supported in the production sandbox, or specific non-supplied functions in standard library modules that are only partly supported. os.umask is but one example of the latter case.