Forums

Web app works but not POST (Contact form)

Hi,

so I managed to get up my little webpage working. It's made in Flask and I added little contact form. Whenever I try to send it, I get Internal Server Error. I went through error log and this is what I get:

2015-03-18 06:14:45,280 :Exception on / [POST]
Traceback (most recent call last):
  File "/home/comatory/VENV/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/comatory/VENV/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/comatory/VENV/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/comatory/VENV/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/comatory/VENV/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/comatory/app/routes.py", line 32, in home
    mail.send(msg)
  File "/home/comatory/VENV/local/lib/python2.7/site-packages/flask_mail.py", line 491, in send
    with self.connect() as connection:
  File "/home/comatory/VENV/local/lib/python2.7/site-packages/flask_mail.py", line 144, in __enter__
    self.host = self.configure_host()
  File "/home/comatory/VENV/local/lib/python2.7/site-packages/flask_mail.py", line 156, in configure_host
    host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
  File "/usr/lib/python2.7/smtplib.py", line 781, in __init__
    SMTP.__init__(self, host, port, local_hostname, timeout)
  File "/usr/lib/python2.7/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 311, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 786, in _get_socket
    new_socket = socket.create_connection((host, port), timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 111] Connection refused

The app runs in virtualenv with newest version of Flask, flask-wtf and flask-mail. It runs fine locally, sending the mail works. I'm using beginner account.

If you have a free account, we block external internet access except for whitelisted sites with pre-defined APIs. This is because we have had users with malicious intent using our platform to spam/do other bad things before.

Oh I see. Is there a way to make an exception for me? I'm just trying to help my little brother out with a school project. I don't mind going with a paid account but I don't think I'd use it for anything else right now.

It looks like the exception is happening when you're trying to send an email? We do support email for free users if they use gmail... https://www.pythonanywhere.com/wiki/SMTPForFreeUsers

OK that's cool, I will use gmail then.

Had a question though... This process won't probably work with 2-step verification right?

That's right, you'll need to set up an app-specific password for your web app. You can do it via the google account security settings page...