title: flaskr GET POST endpoints don't work locally due to incorrect authorization
body: <p>New to flaskr</p>
  
  <p>In Python 3.7</p>
  
  <p>Q1: What database url and password should i use to connect to the database using the database console?</p>
  
  <p>Q2: How do I set the correct credential to do a POST API/curl call?</p>
  
  <p>here is my flaskr.py based on the tutorial here</p>
  
  <p><a href="https://flask.palletsprojects.com/en/1.1.x/" rel="nofollow noreferrer">https://flask.palletsprojects.com/en/1.1.x/</a></p>
  
  <pre><code># all the imports
  import os
  import sqlite3
  from flask import Flask, request, session, g, redirect, url_for, abort, \
       render_template, flash
  
  app = Flask(__name__) # create the application instance :)
  app.config.from_object(__name__) # load config from this file , flaskr.py
  
  # Load default config and override config from an environment variable
  app.config.update(dict(
      DATABASE=os.path.join(app.root_path, 'flaskr.db'),
      # USERNAME='admin',
      # PASSWORD='default'
  ))
  app.config.from_envvar('FLASKR_SETTINGS', silent=True)
  
  def connect_db():
      """Connects to the specific database."""
      rv = sqlite3.connect(app.config['DATABASE'])
      rv.row_factory = sqlite3.Row
      return rv
  
  def get_db():
      """Opens a new database connection if there is none yet for the
      current application context.
      """
      if not hasattr(g, 'sqlite_db'):
          g.sqlite_db = connect_db()
      return g.sqlite_db
  
  @app.teardown_appcontext
  def close_db(error):
      """Closes the database again at the end of the request."""
      if hasattr(g, 'sqlite_db'):
          g.sqlite_db.close()
  
  def init_db():
      db = get_db()
      with app.open_resource('schema.sql', mode='r') as f:
          db.cursor().executescript(f.read())
      db.commit()
  
  @app.cli.command('initdb')
  def initdb_command():
      """Initializes the database."""
      init_db()
      print('Initialized the database.')
  
  
  @app.route('/', methods=['GET'])
  def show_entries():
      db = get_db()
      cur = db.execute('select * from mouse_tracking')
      entries = cur.fetchall()
      # return render_template('show_entries.html', entries=entries)
  
      return entries
  
  @app.route('/add', methods=['POST'])
  def add_entry():
      if not session.get('logged_in'):
          abort(401)
      db = get_db()
      db.execute('insert into mouse_tracking (user_id, date, x, y, click) values (?, ?, ?, ?, ?)',
                   [request.form['user_id'], request.form['date'], request.form['x'], request.form['y']
                       , request.form['click']])
      db.commit()
      flash('New entry was successfully posted')
      return redirect(url_for('show_entries'))
  </code></pre>
  
  <p>So I run </p>
  
  <pre><code>flask initdb
  
  flask run
  </code></pre>
  
  <p>Return</p>
  
  <ul>
  <li>Serving Flask app "flaskr"</li>
  <li>Forcing debug mode on</li>
  <li>Running on <a href="http://127.0.0.1:5000/" rel="nofollow noreferrer">http://127.0.0.1:5000/</a> (Press CTRL+C to quit)</li>
  <li>Restarting with stat</li>
  <li>Debugger is active!</li>
  <li>Debugger PIN: 313-915-097</li>
  </ul>
  
  <p>Then I do a POST curl call trying to write the data into the database</p>
  
  <pre><code>curl --location --request POST 'http://localhost:5000/add' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Basic Og==' \
  --data-raw '{
      "user_id": "1",
      "date": "2020-01-01",
      "x":"720",
      "y":"50",
      "click":"0"
  }'
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&gt;
  &lt;title&gt;401 Unauthorized&lt;/title&gt;
  &lt;h1&gt;Unauthorized&lt;/h1&gt;
  &lt;p&gt;The server could not verify that you are authorized to access the URL requested. You either supplied the wrong
      credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.&lt;/p&gt;
  </code></pre>
  
  <p>replacing the url into  </p>
  
  <pre><code>http://127.0.0.1:5000/add
  </code></pre>
  
  <p>result the same error</p>
  
  <p>Wonder if anyone could help? Thank you!</p>