I use flask, an api and SQLAlchemy with SQLite. I begin in python and flask and i have problem with the list.
My application work, now i try a news functions. I need to know if my json informations are in my db. The function find_current_project_team() get information in the API.
def find_current_project_team():
headers = {"Authorization" : "bearer "+session['token_info']['access_token']}
user = requests.get("https://my.api.com/users/xxxx/", headers = headers)
user = user.json()
ids = [x['id'] for x in user]
return(ids)
I use ids = [x['id'] for x in user]
(is the same that) :
ids = []
for x in user:
ids.append(x['id'])
To get ids
information. Ids information are id in the api, and i need it.
I have this result :
[2766233, 2766237, 2766256]
I want to check the values ONE by One in my database. If the values doesn't exist, i want to add it. If one or all values exists, I want to check and return "impossible sorry, the ids already exists".
For that I write a new function:
def test():
test = find_current_project_team()
for find_team in test:
find_team_db = User.query.filter_by(
login=session['login'], project_session=test
).first()
I have absolutely no idea to how check values one by one.
If someone can help me, thanks you :)
Actually I have this error :
sqlalchemy.exc.InterfaceError: (InterfaceError) Error binding parameter 1 - probably unsupported type. 'SELECT user.id AS user_id, user.login AS user_login, user.project_session AS user_project_session \nFROM user \nWHERE user.login = ? AND user.project_session = ?\n LIMIT ? OFFSET ?' ('my_tab_login', [2766233, 2766237, 2766256], 1, 0)