title: Python - Flask Validate SelectField
body: <p>i'm novel in the python world  and i'm trying to use the external APIs with google apple engine, i would like make a form validate with a selectField filled with a json response of Api.</p>
  
  <p>This is my code</p>
  
  <pre><code>class CommentForm(FlaskForm):
      name = StringField('Nome', [required()])
      nazionalita = SelectField('Nazionalita',[required()])
      eta = IntegerField('Eta', [required()])
      Comment = TextAreaField('Commento', [required()])
      Data = DateTimeField('Data',[required()],format='%d/%m/%Y', )
      submit = SubmitField('Inserisci', [required()])
  
      def validate_nazionalita(form):
         if  not form.nazionalita.data == None:
            raise ValidationError('Nazionalita non selezionata')
  
  @app.route('/insert', methods=['GET'])
  def insert():
      form = CommentForm()
      url = 'https://ajayakv-rest-countries-v1.p.mashape.com/rest/v1/all'
      req = urllib2.Request(url)
      req.add_header('X-Mashape-Key', MASHAPE_KEY)
      req.add_header('Accept', 'application/json')
      urlresponse = urllib2.urlopen(req)
      content = urlresponse.read()
  
      responde = make_response(content)
  
      responde.headers['content-type']='application/json'
      data = json.loads(responde.data)
      nation = list(data)
      scelte =[]
      scelte =  ([( s['callingCodes'] , s['name'] )for s in nation])
      form.nazionalita.choices= scelte
      return  render_template('insert.html', form=form)
  
  
  @app.route('/insert', methods=['POST'])
  def submit():
      form = CommentForm(request.form)
      if not form.validation():
          return render_template('insert.html', form=form), 400
      return redirect('/')
  </code></pre>
  
  <p>and this is html page :</p>
  
  <pre><code>&lt;form method="post" action="/insert"&gt;
        {{ form.csrf_token }}
        &lt;div&gt; {{form.name.label}}: {{form.name}}  &lt;/div&gt;
  
          {% if form.name.errors %}
              &lt;ul class=errors&gt;
                  {% for error in form.name.errors %}
                      &lt;li&gt;{{ error }}&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          {% endif %}
  
  
        &lt;div&gt; {{form.nazionalita.label}}: {{form.nazionalita}} &lt;/div&gt;
  
          {% if form.nazionalita.errors %}
              &lt;ul class=errors&gt;
                  {% for error in form.nazionalita.errors %}
                      &lt;li&gt;{{ error }}&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          {% endif %}
  
        &lt;div&gt; {{form.eta.label}}: {{form.eta}} &lt;/div&gt;
  
          {% if form.eta.errors %}
              &lt;ul class=errors&gt;
                  {% for error in form.eta.errors %}
                      &lt;li&gt;{{ error }}&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          {% endif %}
  
        &lt;div&gt; {{form.Data.label}}: {{form.Data}} &lt;/div&gt;
  
          {% if form.Data.errors %}
              &lt;ul class=errors&gt;
                  {% for error in form.Data.errors %}
                      &lt;li&gt;{{ error }}&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          {% endif %}
  
        &lt;div&gt; {{form.Comment.label}}: {{form.Comment}} &lt;/div&gt;
  
          {% if form.Comment.errors %}
              &lt;ul class=errors&gt;
                  {% for error in form.Comment.errors %}
                      &lt;li&gt;{{ error }}&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          {% endif %}
  
        &lt;div&gt; {{form.submit}} &lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>if i remove the selectField all work well , but with it the error is :</p>
  
  <pre><code>    `Traceback (most recent call last):
       File "/home/roberto/Scrivania/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 267, in Handle
       result = handler(dict(self._environ), self._StartResponse)
       File "/home/roberto/Scrivania/simulazione/lib/flask/app.py", line 1994, in __call__
       return self.wsgi_app(environ, start_response)
       File "/home/roberto/Scrivania/simulazione/lib/flask/app.py", line 1985, in wsgi_app
       response = self.handle_exception(e)
       File "/home/roberto/Scrivania/simulazione/lib/flask/app.py", line 1540, in handle_exception
       reraise(exc_type, exc_value, tb)
       File "/home/roberto/Scrivania/simulazione/lib/flask/app.py", line 1982, in wsgi_app
       response = self.full_dispatch_request()
       File "/home/roberto/Scrivania/simulazione/lib/flask/app.py", line 1614, in full_dispatch_request
       rv = self.handle_user_exception(e)
       File "/home/roberto/Scrivania/simulazione/lib/flask/app.py", line 1517, in handle_user_exception
       reraise(exc_type, exc_value, tb)
       File "/home/roberto/Scrivania/simulazione/lib/flask/app.py", line 1612, in full_dispatch_request
       rv = self.dispatch_request()
       File "/home/roberto/Scrivania/simulazione/lib/flask/app.py", line 1598, in dispatch_request
       return self.view_functions[rule.endpoint](**req.view_args)
       File "/home/roberto/Scrivania/simulazione/app/handlers/insert.py",  line 46, in submit
       if not form.validate():
       File "/home/roberto/Scrivania/simulazione/lib/wtforms/form.py", line 310, in validate
       return super(Form, self).validate(extra)
       File "/home/roberto/Scrivania/simulazione/lib/wtforms/form.py", line 152, in validate
       if not field.validate(self, extra):
       File "/home/roberto/Scrivania/simulazione/lib/wtforms/fields/core.py", line 193, in validate
       self.pre_validate(form)
       File "/home/roberto/Scrivania/simulazione/lib/wtforms/fields/core.py", line 468, in pre_validate
       for v, _ in self.choices:
       TypeError: 'NoneType' object is not iterable`
  </code></pre>
  
  <p>and i dont understand why e how resolved this.<br>
  thank you all.</p>