title: Flask - "ValueError: Detected newline in header value. This is a potential security prob lem"
body: <p>I'm new to python and am playing around with flask and have built a copy of what's taught on one of the udacity courses where you can upload ASCII art to a pretty basic web page.</p>
  
  <p>After playing around I noticed that I'm getting an error when I upload ASCII art that says:</p>
  
  <p><strong><em>ValueError: Detected newline in header value.  This is a potential security problem</em></strong></p>
  
  <p>I have no clue what the issue is, I've attached both the code and request headers below:</p>
  
  <p>Headers: <a href="http://imgur.com/w3oaROB" rel="nofollow">http://imgur.com/w3oaROB</a></p>
  
  <pre><code>from flask import Flask, render_template, redirect, url_for, request, flash, request
  from datetime import datetime
  import sqlite3
  import os
  from os.path import expanduser
  app = Flask(__name__)
  
  
  def fetch(name):
      conn = sqlite3.connect('art.db')
      cursor = conn.cursor()
      cursor.execute("SELECT * from {} ORDER BY created DESC".format(name))
      return cursor
  
  def insert(title, art):
      time = datetime.now()
      conn = sqlite3.connect('art.db')
      cursor = conn.cursor()
      cursor.execute("""INSERT INTO art VALUES (?,?,?)""",(title, art,time))
      conn.commit()
  
  def delete(title):
      conn = sqlite3.connect('art.db')
      cursor = conn.cursor()
      cursor.execute("""DELETE FROM art WHERE title = '{}'""".format(title))
      conn.commit()
  
  
  def render_front(title='', art='', error='', posts=''):
      return render_template('front.html',title=title, art=art, error=error, posts=posts)
  
  def get_posts(table):
      x = fetch(table)
      posts = [i for i in x]
      return posts
  
  @app.route('/post/&lt;title&gt;/&lt;art&gt;', methods=['GET','POST'])
  def new_post(title=None,art=None):
      if request.method == 'POST':
          if request.form.getlist('hidden'):
              title = request.form['hidden']
              delete(title)
              posts = get_posts('art')
              return render_front(posts=posts)
          elif request.form.getlist('titles'):
              title = request.form['titles']
              art = request.form['arts']
              if title and art:
                  insert(str(title), str(art))
                  return redirect('/post/{}/{}'.format(title,art))
              else:
                  error = 'ERROR SOMEWHERE'
                  return render_front(error=error, art=art, title=title)
      else:
          posts = [[title,art]]
          return render_front(posts=posts)
  
  @app.route('/', methods=['GET','POST'])
  def home():
      if request.method == 'POST':
          if request.form.getlist('hidden'):
              title = request.form['hidden']
              delete(title)
              posts = get_posts('art')
              return render_front(posts=posts)
          elif request.form.getlist('titles'):
              title = request.form['titles']
              art = request.form['arts']
              if title and art:
                  insert(str(title), str(art))
                  return redirect('/post/{}/{}'.format(title,art))
              else:
                  error = 'ERROR SOMEWHERE'
                  return render_front(error=error, art=art, title=title)
      else:
          posts = get_posts('art')
          return render_front(posts=posts)
  
  
  if __name__ == '__main__':
      app.debug = True
      app.run()
  </code></pre>