Scheduler won't run with request.requires_https()

184 views
Skip to first unread message

Yarin

unread,
Jun 21, 2012, 12:15:32 PM6/21/12
to web...@googlegroups.com
I can't get the scheduler to run when I turn on request.requires_https().

$ /opt/web-apps/web2py/web2py.py -K myapp


Result:

starting scheduler for "myapp"...
Currently running 1 scheduler processes
Processes started
Process Process-1:
Traceback (most recent call last):
  File "/usr/lib64/python2.6/multiprocessing/process.py", line 232, in _bootstrap
    self.run()
  File "/usr/lib64/python2.6/multiprocessing/process.py", line 88, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/web-apps/web2py/gluon/shell.py", line 189, in run
    _env = env(a, c=c, import_models=import_models)
  File "/opt/web-apps/web2py/gluon/shell.py", line 131, in env
    run_models_in(environment)
  File "/opt/web-apps/web2py/gluon/compileapp.py", line 513, in run_models_in
    restricted(code, environment, layer=model)
  File "/opt/web-apps/web2py/gluon/restricted.py", line 205, in restricted
    exec ccode in environment
  File "applications/myapp/models/db.py", line 10, in <module>
    request.requires_https()
  File "/opt/web-apps/web2py/gluon/globals.py", line 119, in requires_https
    redirect(URL(scheme='https', args=self.args, vars=self.vars))
  File "/opt/web-apps/web2py/gluon/http.py", line 128, in redirect
    Location=location)
HTTP: 303 SEE OTHER

LAMP/mod_wsgi environment. Anyone deal with this already?


Massimo Di Pierro

unread,
Jun 21, 2012, 2:36:23 PM6/21/12
to web...@googlegroups.com
You have this line in 

    request.requires_https()

In

myapp/models/db.py", line 10, in <module>

it prevents the scheduler form importing the modules.

Yarin Kessler

unread,
Jun 21, 2012, 3:57:58 PM6/21/12
to web...@googlegroups.com
Massimo- I don't understand your answer- My question was about how to run scheduler WITH request.requires_https() turned on. Are you saying this is not possible? 

My main app needs https protection. My scheduler makes use of the db/models/methods of the main app, so what is your recommendation? Do I need to separate the scheduler into a separate app and make cross-app calls?

--

Niphlod

unread,
Jun 21, 2012, 4:05:50 PM6/21/12
to web...@googlegroups.com
actually it's not possible, but as a hint, can't you enforce https at the webserver level ?
Or, you could "protect" standard controllers putting request.requires_https() in those, so scheduler could access your tasks in models without "hitting" that wall.

Anthony

unread,
Jun 21, 2012, 4:06:44 PM6/21/12
to web...@googlegroups.com
Would something like this work:

cmd_options = request.global_settings.cmd_options
if not (cmd_options and cmd_options.scheduler):
    request
.requires_https()

Should we add a test for the scheduler to requires_https (and maybe add a global_settings.scheduler, like global_settings.cronjob): http://code.google.com/p/web2py/source/browse/gluon/globals.py#127?

Anthony

Yarin

unread,
Jun 21, 2012, 4:20:44 PM6/21/12
to web...@googlegroups.com
Anthony and Niphlod- Thanks, two good solutions. Just tried Anthony's code and it's working. And yea I think that the scheduler should be tested for within requires_https()

Andrew

unread,
Jun 21, 2012, 5:47:37 PM6/21/12
to web...@googlegroups.com
I guess these are new features.  I just tried to read about them - would be good to see them added to the book (The core).
Reply all
Reply to author
Forward
0 new messages