1

I'm currently working on my final project. I know that the number of people who will be able to answer this question is small, but it won't hurt to ask. So here it is: for some reason,

user_email = request.form.get("email")

is returning None. I know this because my I get the error 'Nonetype object is not iterable' when running my webpage, pointing to this line:

server.sendmail('team.brickdealer@gmail.com', user_email, code)

But first, let me give you some background on my code. The section of python code that may carry the problem is my register function. Although its not completely done, the point of this function is to get an email and password, and then to send a randomly generated confirmation code to the email passed in. (I'll deal with accepting the confirmation code and the rest of the registration process later.) My html, on the other hand, is modeled after form3 of the source code following week 10's lecture. Basically, it uses a bootstrap library of css and html for form validation on the client side (and looks very nice as well). Here's the documentation of the validator. I'll also post my layout.html file, in case this has anything to do with the problem. Here's all the source code:

Python File:

@app.route("/register", methods=["GET", "POST"])
def register():
    if request.method == "POST":
        user_email = request.form.get("email")
        user_password = request.form.get("password")
        db.execute("INSERT INTO users(email, password) VALUES(:email, :password)", email=user_email, password=user_password)

        code = str(random.randint(100000000, 999999999))
        db.execute("INSERT INTO codes(code) VALUES(:code)", code=code)

        message = "Here is your access code to register with BrickDealer: %s. Thanks for choosing us!" % code
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.starttls()
        server.login('team.brickdealer@gmail.com', 'Don't wanna give my password out :)')
        server.sendmail('team.brickdealer@gmail.com', user_email, code)
    else:
        return render_template("register.html")

register.html:

{% extends "layout.html" %}

  {% block title %}
      Register
  {% endblock %}

  {% block main %}
  <form action="{{ url_for('register') }}" method="post">
      <html>
          <head>
              <!-- http://1000hz.github.io/bootstrap-validator/ -->
              <title>Register</title>

      <form data-toggle="validator" role="form">
        <div class="form-group">
          <label for="inputEmail" class="control-label">Email</label>
          <input type="email" class="form-control" id="inputEmail" name: "email" placeholder="example@gmail.com" data-error="Invalid Email Address" required>
          <div class="help-block">Only accepts gmail accounts</div>
          <div class="help-block with-errors"></div>
        </div>
        <div class="form-group">
          <label for="inputPassword" class="control-label">Password</label>
            <div class="form-group">
              <input type="password" data-minlength="6" class="form-control" id="inputPassword" name:"password" placeholder="examplepassword" required>
              <div class="help-block">Minimum of 6 characters</div>
            </div>
            <div class="form-group">
                <label for="inputPassword" class="control-label">Confirm Password</label>
              <input type="password" class="form-control" id="inputPasswordConfirm" data-match="#inputPassword" data-match-error="Password and confirmation do not match" placeholder="examplepassword" required>
              <div class="help-block">Must match password</div>
              <div class="help-block with-errors"></div>
            </div>
        </div>
        <div class="form-group">
          <button type="submit" class="btn btn-primary">Submit</button>
        </div>
      </form>

  {% endblock %}

And layout.html (phew):

<html lang="en">

    <head>

        <!-- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta -->
        <meta charset="utf-8"/>
        <meta content="initial-scale=1, width=device-width" name="viewport"/>

        <!-- documentation at http://getbootstrap.com/, alternative themes at https://www.bootstrapcdn.com/bootswatch/ -->

        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

        <script src="https://code.jquery.com/jquery-latest.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.5/validator.min.js"></script>

        <title>BrickDealer: {% block title %}{% endblock %}</title>

    </head>

    <body>

        <div class="container">

            <nav class="navbar navbar-default">
                <div class="container-fluid">
                    <div class="navbar-header">
                        <button aria-expanded="false" class="navbar-toggle collapsed" data-target="#navbar" data-toggle="collapse" type="button">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="{{ url_for('index') }}"></span><span class="white">BrickDealer</span></a>
                    </div>
                    <div class="collapse navbar-collapse" id="navbar">
                        {% if session.user_id %}
                            <ul class="nav navbar-nav">
                                <li><a href="{{ url_for('index') }}">Main</a></li>
                                <li><a href="{{ url_for('sets') }}">Sets</a></li>
                                <li><a href="{{ url_for('set_info') }}">Set Info</a></li>
                                <li><a href="{{ url_for('help') }}">Help</a></li>
                                <li><a href="{{ url_for('about') }}">About</a></li>
                            </ul>
                            <ul class="nav navbar-nav navbar-right">
                                <li><a href="{{ url_for('logout') }}">Log Out</a></li>
                            </ul>
                        {% else %}
                            <ul class="nav navbar-nav navbar-right">
                                <li><a href="{{ url_for('register') }}">Register</a></li>
                                <li><a href="{{ url_for('login') }}">Log In</a></li>
                            </ul>
                        {% endif %}
                    </div>
                </div>
            </nav>

            {% if get_flashed_messages() %}
                <header>
                    <div class="alert alert-info" role="alert">
                        {{ get_flashed_messages() | join(" ") }}
                    </div>
                </header>
            {% endif %}

            <main>
                {% block main %}{% endblock %}
            </main>

        </div>

    </body>

</html>

If you've read all the way down here, thanks for sticking through and reading my problem! I hope you can help me get past this obstacle.

3

Suggestion: validate your register.html with Nu Html Checker. (Right-click, view source, copy, paste into the checker). It should complain about the typo in this line
<input type="email" class="form-control" id="inputEmail" name: "email" placeholder="example@gmail.com" data-error="Invalid Email Address" required>

1
  • Thanks a lot! I can't believe I missed that. :P – Jason_V Aug 1 '17 at 17:49
0

NoneType basically means your variable(called names in python) doesn't have any assigned value.

In user_email = request.form.get(email) the email has to be passed as string under double quotes. user_email = request.form.get("email").

Due to this user_email does not get assigned to any value, thus the NoneType which causes error in the subsequent code.

1
  • Thank you for the answer, but this was, unfortunately not the answer I was looking for. This is my fault; in the code snipit above the main code blocks I forgot the quotes around email as you said, but in the actual code, they were already there. :( I've edited the small code snipit to be correct. So kudos to you on catching that error, but it was not actually in my code. Again, sorry! – Jason_V Aug 1 '17 at 4:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .