Forums

Flask reCAPTCHA -- internal server error

So I can run the reCAPTCHA on localhost, but when I load it onto PythonAnywhere, I get an internal server error navigating to the page with the captcha that I cannot figure out. The output from error.log is:

2015-10-03 05:44:24,842 :Exception on /contact [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/socalnspweb/mysite/flask_app.py", line 114, in contact
    return render_template('contact.html', pageTitle="Contact Us", form=form, emails=emails, nth_selected=nSelected)
  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 125, in render_template
    context, ctx.app)
  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 107, in _render
    rv = template.render(context)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/socalnspweb/mysite/static/templates/contact.html", line 1, in top-level template code
    {% extends "header.html" %}
  File "/home/socalnspweb/mysite/static/templates/header.html", line 118, in top-level template code
    {% block content %}
  File "/home/socalnspweb/mysite/static/templates/contact.html", line 70, in block "content"
    {{ form.recaptcha }}
  File "/usr/local/lib/python2.7/dist-packages/wtforms/fields/core.py", line 131, in __html__
    return self()
  File "/usr/local/lib/python2.7/dist-packages/wtforms/fields/core.py", line 140, in __call__
    return self.widget(self, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask_wtf/recaptcha/widgets.py", line 68, in __call__
    'visual_challenge':    _('Get a visual challenge'),
  File "/usr/local/lib/python2.7/dist-packages/flaskext/babel.py", line 456, in gettext
    t = get_translations()
  File "/usr/local/lib/python2.7/dist-packages/flaskext/babel.py", line 194, in get_translations
    translations = support.Translations.load(dirname, [get_locale()])
  File "/usr/local/lib/python2.7/dist-packages/flaskext/babel.py", line 209, in get_locale
    babel = ctx.app.extensions['babel']
KeyError: 'babel'

Not sure how to interpret this error, as I can import babel through Python in a bash console.

Looks like it might be this bug. Could you try upgrading Flask-WTF by running this from a bash prompt?

pip2.7 install --user --upgrade Flask-WTF

That did it. Thanks!

Excellent, thanks for confirming!

I'm having a very similar problem, see log, had Flask-WTF installed but wasn't using it so I moved the webapp to a fresh venv with only Flask, flask-table and flask_qrcodes installed, same basic problem as shown below:

2018-06-08 21:30:12,121: [2018-06-08 21:30:12,114] ERROR in app: Exception on /checkin_home/ [POST]
2018-06-08 21:30:12,121: Traceback (most recent call last):
2018-06-08 21:30:12,121:   File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1982, in wsgi_app
2018-06-08 21:30:12,121:     response = self.full_dispatch_request()
2018-06-08 21:30:12,121:   File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1614, in full_dispatch_request
2018-06-08 21:30:12,122:     rv = self.handle_user_exception(e)
2018-06-08 21:30:12,122:   File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1517, in handle_user_exception
2018-06-08 21:30:12,122:     reraise(exc_type, exc_value, tb)
2018-06-08 21:30:12,122:   File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 33, in reraise
2018-06-08 21:30:12,122:     raise value
2018-06-08 21:30:12,122:   File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1612, in full_dispatch_request
2018-06-08 21:30:12,122:     rv = self.dispatch_request()
2018-06-08 21:30:12,122:   File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1598, in dispatch_request
2018-06-08 21:30:12,123:     return self.view_functions[rule.endpoint](**req.view_args)
2018-06-08 21:30:12,123:   File "/my/working_dir/path/mysite/project/mci.py", line 49, in checkin_home_post
2018-06-08 21:30:12,123:     return checkin_search_module.checkin_search(event_guid=event_guid, input_string=input_string)
2018-06-08 21:30:12,123:   File "/my/working_dir/path/mysite/project/checkin_search_module.py", line 3, in checkin_search
2018-06-08 21:30:12,123:     from flask_table import Table, Col
2018-06-08 21:30:12,123:   File "/my/working_dir/path/.local/lib/python3.6/site-packages/flask_table/__init__.py", line 1, in <module>
2018-06-08 21:30:12,123:     from .table import Table, create_table
2018-06-08 21:30:12,123:   File "/my/working_dir/path/.local/lib/python3.6/site-packages/flask_table/table.py", line 8, in <module>
2018-06-08 21:30:12,124:     from .columns import Col
2018-06-08 21:30:12,124:   File "/my/working_dir/path/.local/lib/python3.6/site-packages/flask_table/columns.py", line 161, in <module>
2018-06-08 21:30:12,124:     class BoolCol(OptCol):
2018-06-08 21:30:12,124:   File "/my/working_dir/path/.local/lib/python3.6/site-packages/flask_table/columns.py", line 166, in BoolCol
2018-06-08 21:30:12,124:     yes_display = _('Yes')
2018-06-08 21:30:12,124:   File "/usr/local/lib/python3.6/dist-packages/flask_babel/__init__.py", line 539, in gettext
2018-06-08 21:30:12,124:     t = get_translations()
2018-06-08 21:30:12,124:   File "/usr/local/lib/python3.6/dist-packages/flask_babel/__init__.py", line 214, in get_translations
2018-06-08 21:30:12,124:     babel = current_app.extensions['babel']
2018-06-08 21:30:12,125: KeyError: 'babel'

if you look at the most recent builds for flask_table, it certainly seems like there was some problems with babel. perhaps double check your flask_table version is the most updated one?

I did try updating flask-table, even made a new venv and did it all from scratch to rule out it being some other module causing a problem, didn't help. I'm going to assume it's a problem in flask-table and hopefully gets addressed in a future build. I was able to reconfigure the output as a <ul> instead, and just cut flask-table out of the application for now, but I hope I can come back to it in the future.