ProtoFeather
06/11/2022, 5:38 PMzachtsk
06/11/2022, 6:47 PMProtoFeather
06/11/2022, 8:11 PManand
06/12/2022, 10:54 AManand
06/12/2022, 10:57 AMtry: ... except
ProtoFeather
06/12/2022, 12:31 PMfor item in api_list:
try:
supabase.table("suchmeme").insert(item).execute()
print(f'Inserted meme {item["id"]} to Supabase DB')
post(item)
except Exception as e:
print(e)
if 'duplicate key value violates unique constraint' in str(e):
print("Meme already exists")
continue
else:
print(f'Error upon inserting data in DB with meme {item["id"]} due to {e}')
continue
ProtoFeather
06/12/2022, 12:32 PMProtoFeather
06/12/2022, 12:32 PM{'message': 'duplicate key value violates unique constraint "suchmeme_pkey"', 'code': '23505', 'details': 'Key (id)=(6396) already exists.', 'hint': None}
ProtoFeather
06/12/2022, 12:33 PM<class 'postgrest.exceptions.APIError'>
anand
06/12/2022, 2:10 PManand
06/12/2022, 2:11 PMexcept Exception
anand
06/12/2022, 2:12 PManand
06/12/2022, 2:13 PMpy
...
except APIError as e:
if e.code == "23505":
# do stuff
ProtoFeather
06/12/2022, 2:13 PM