I am making my first Python/Flask API. I am currently working on my post request that should take in a JSON object that looks like the following. Every value should be either an integer or null based off user input.
{
"FIDE": {
"standard": 1555,
"rapid": 1500,
"blitz": null
},
"USCF": {
"regular": null,
"quick": null,
"blitz": null
},
"Chesscom": {
"bullet": null,
"blitz": 1556,
"rapid": 1601,
"daily": null,
"puzzle": null
},
"LiChess": {
"bullet": null,
"blitz": null,
"rapid": null,
"classical": null,
"correspondence": null,
"training": null
}
}
That input should then hit this basic flask app. I should note that I just created the model and I'm not sure if I'm handling an object with a depth greater than one correctly.
from flask import Flask , request, redirect, url_for, Response
from flask_sqlalchemy import SQLAlchemy
import json
app = Flask(__name__)
db= SQLAlchemy(app)
class Player(db.model):
__tablename__ = 'Players'
id = db.Column(db.Integer, primary_key=True)
FIDE.standard(db.Integer, nullable = True)
FIDE.rapid(db.Integer, nullable = True)
FIDE.blitz(db.Integer, nullable = True)
USCF.regular(db.Integer, nullable = True)
USCF.quick(db.Integer, nullable = True)
USCF.blitz(db.Integer, nullable = True)
Chesscom.bullet(db.Integer, nullable = True)
Chesscom.blitz(db.Integer, nullable = True)
Chesscom.rapid(db.Integer, nullable = True)
Chesscom.daily(db.Integer, nullable = True)
Chesscom.puzzle(db.Integer, nullable = True)
Lichess.bullet(db.Integer, nullable = True)
Lichess.blitz(db.Integer, nullable = True)
Lichess.rapid(db.Integer, nullable = True)
Lichess.correspondence(db.Integer, nullable = True)
Lichess.training(db.Integer, nullable = True)
@app.route('/')
def index():
return 'Hello David'
@app.route('/add', methods = ['POST'])
def add(Player):
request_data= Player.getjson()
response = Response(request_data.FIDE.standard, status=200, mimetype='application/json')
return response
When I send a request to Postman I get an error message back saying
TypeError: exceptions must derive from BaseException
I believe, this is the relevant part of the error message, but I could be wrong. I will indclude the full error below. However, does anyone know what I am doing wrong within my app.py file?
Here is the full error message
Traceback (most recent call last):
File "C:\Users\dreke\Documents\coding\sideProject\chess-backend\venv\Lib\site-packages\flask\cli.py", line 354, in __call__
self._flush_bg_loading_exception()
File "C:\Users\dreke\Documents\coding\sideProject\chess-backend\venv\Lib\site-packages\flask\cli.py", line 342, in _flush_bg_loading_exception
raise exc_info
TypeError: exceptions must derive from BaseException