librelist archives

« back to archive

login_required issue when running a Flask app on GAE

login_required issue when running a Flask app on GAE

From:
mat --
Date:
2010-10-06 @ 16:43
Hello,

I am new to Flask (and like it a lot). I am having an issue while running a
Flask-based app on GAE.

I am using the (excellent) boilerplate project template available on
http://github.com/kamalgill/flask-appengine-template.

The app works just fine when running the app with `dev_appserver.py`.

It also works fine when running `appcfg.py update` --for an app created in
the "Open to all Google Accounts users" mode.

The issue is seen only for an app that was created in the "Restricted to the
following Google Apps <http://www.google.com/a> domain" mode, selected in
the "Authentication Options".

It seems then that any url decorated with @login_required will generate an
`Internal Server Error`.

Here is an example of the error log I get in GAE admin after visiting an url
decorated with the@login_required decorator:

Exception on /example/new [GET]

Traceback (most recent call last):
  File "/base/data/home/apps/flask88/1.345306240891604377/flask/app.py",
line 861, in wsgi_app
    rv = self.dispatch_request()
  File "/base/data/home/apps/flask88/1.345306240891604377/flask/app.py",
line 696, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File 
"/base/data/home/apps/flask88/1.345306240891604377/application/decorators.py",
line 16, in decorated_view
    return redirect(users.create_login_url(request.url))
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/users.py",
line 223, in create_login_url
    raise NotAllowedError
NotAllowedError

Code for the /example/new url is as follows:

@app.route('/example/new', methods = ['GET', 'POST'])
@login_required
def new_example():
    form = ExampleForm()
    if form.validate_on_submit():
        example = ExampleModel(
                    example_id = form.example_id.data,
                    example_title = form.example_title.data,
                    added_by = users.get_current_user()
                    )
        example.put()
        flash('Example successfully saved.')
        return redirect(url_for('list_examples'))
    return render_template('new_example.html', form=form)

I don't think this is specific to my app since I can reproduce the same
issue when deploying on GAE the sample app available on
http://github.com/kamalgill/flask-appengine-template

Is this an issue with the login_required decorator? Anyone knows how
to fix this?

Mat

Re: [flask] login_required issue when running a Flask app on GAE

From:
Charlie Knudsen
Date:
2010-10-07 @ 03:36
Hi Mat,
Seems like maybe you my be running into the error described here.  
http://code.google.com/p/googleappengine/issues/detail?id=1058

The fix that is used to work around it is in comment 8, and points to the 
URL below:
http://code.google.com/appengine/articles/domains.html

Just a guess however.  Hope it helps.

Charlie
 
On Oct 6, 2010, at 11:43 AM, mat -- <mat88h@gmail.com> wrote:

> Hello,
> 
> I am new to Flask (and like it a lot). I am having an issue while 
running a Flask-based app on GAE.
> 
> I am using the (excellent) boilerplate project template available on 
http://github.com/kamalgill/flask-appengine-template.
> 
> The app works just fine when running the app with `dev_appserver.py`. 
> 
> It also works fine when running `appcfg.py update` --for an app created 
in the "Open to all Google Accounts users" mode.
> 
> The issue is seen only for an app that was created in the "Restricted to
the following Google Apps domain" mode, selected in the "Authentication 
Options".
> 
> It seems then that any url decorated with @login_required will generate 
an `Internal Server Error`.
> 
> Here is an example of the error log I get in GAE admin after visiting an
url decorated with the@login_required decorator:
> 
> Exception on /example/new [GET]
> Traceback (most recent call last):
>   File "/base/data/home/apps/flask88/1.345306240891604377/flask/app.py",
line 861, in wsgi_app
>     rv = self.dispatch_request()
>   File "/base/data/home/apps/flask88/1.345306240891604377/flask/app.py",
line 696, in dispatch_request
>     return self.view_functions[rule.endpoint](**req.view_args)
>   File 
"/base/data/home/apps/flask88/1.345306240891604377/application/decorators.py",
line 16, in decorated_view
>     return redirect(users.create_login_url(request.url))
>   File 
"/base/python_runtime/python_lib/versions/1/google/appengine/api/users.py",
line 223, in create_login_url
>     raise NotAllowedError
> NotAllowedError
> Code for the /example/new url is as follows:
> @app.route('/example/new', methods = ['GET', 'POST'])
> 
> @login_required
> def new_example():
> 
>     form = ExampleForm()
>     if form.validate_on_submit():
> 
>         example = ExampleModel(
>                     example_id = form.example_id.data,
> 
>                     example_title = form.example_title.data,
> 
>                     added_by = users.get_current_user()
> 
>                     )
>         example.put()
> 
>         flash('Example successfully saved.')
>         return redirect(url_for('list_examples'))
> 
>     return render_template('new_example.html', form=form)
> 
> I don't think this is specific to my app since I can reproduce the same 
issue when deploying on GAE the sample app available on 
http://github.com/kamalgill/flask-appengine-template
> 
> Is this an issue with the login_required decorator? Anyone knows how to 
fix this?
> 
> Mat
> 

Re: [flask] login_required issue when running a Flask app on GAE

From:
mat --
Date:
2010-10-07 @ 07:51
Hi Charlie,
You are absolutely right. The fix is here:
http://code.google.com/appengine/articles/domains.html
After reading again the documentation, I also realized that when restricting
an app to a particular domain name, I needed first to "add" that domain to
my app.
After adding the domain name, the  `Internal Server Error` is gone and all
seems to work just fine :-)
Thanks.
Mat

On Thu, Oct 7, 2010 at 5:36 AM, Charlie Knudsen
<charlie.knudsen@gmail.com>wrote:

> Hi Mat,
> Seems like maybe you my be running into the error described here.
> http://code.google.com/p/googleappengine/issues/detail?id=1058
>
> The fix that is used to work around it is in comment 8, and points to the
> URL below:
> http://code.google.com/appengine/articles/domains.html
>
> Just a guess however.  Hope it helps.
>
> Charlie
>
> On Oct 6, 2010, at 11:43 AM, mat -- <mat88h@gmail.com> wrote:
>
> Hello,
>
> I am new to Flask (and like it a lot). I am having an issue while running a
> Flask-based app on GAE.
>
> I am using the (excellent) boil erplate project template available on
> <http://github.com/kamalgill/flask-appengine-template>
> http://github.com/kamalgill/flask-appengine-template.
>
> The app works just fine when running the app with `dev_appserver.py`.
>
> It also works fine when running `appcfg.py update` --for an app created in
> the "Open to all Google Accounts users" mode.
>
> The issue is seen only for an app that was created in the "Restricted to
> the following Google Apps <http://www.google.com/a> domain" mode, selected
> in the "Authentication Options".
>
> It seems then that any url decorated with @login_required will generate an
> `Internal Server Error`.
>
> Here is an example of the error log I get in GAE admin after visiting an
> url decorated with the@login_required decorator:
>
> Exception on /example/new [GET]
>
> Traceback (most recent call last):
>   File "/base/data/home/apps/flask88/1.345306240891604377/flask/app.py",
line 861, in wsgi_app
>     rv = self.dispatch_request()
>   File "/base/data/home/apps/flask88/1.345306240891604377/flask/app.py",
line 696, in dispatch_request
>     return self.view_functions[rule.endpoint](**req.view_args)
>   File 
"/base/data/home/apps/flask88/1.345306240891604377/application/decorators.py",
line 16, in decorated_view
>     return redirect(users.create_login_url(request.url))
>   File 
"/base/python_runtime/python_lib/versions/1/google/appengine/api/users.py",
line 223, in create_login_url
>     raise NotAllowedError
> NotAllowedError
>
> Code for the /example/new url is as follows:
>
> @app.route('/example/new', methods = ['GET', 'POST'])
> @login_required
> def new_example():
>
>     form = ExampleForm()
>     if form.validate_on_submit():
>         example = ExampleModel(
>                     example_id = form.example_id.data,
>                     example_title = form.example_title.data,
>                     added_by = users.get_current_user()
>                     )
>         example.put()
>         flash('Example successfully saved.')
>         return redirect(url_for('list_examples'))
>     return render_template('new_example.html', form=form)
>
> I don't think this is specific to my app since I can reproduce the same
> issue when deploying on GAE the sample app available on
> <http://github.com/kamalgill/flask-appengine-template>
> http://github.com/kamalgill/flask-appengine-template
>
> Is this an issue with the login_required decorator? Anyone knows how
> to fix this?
>
> Mat
>
>