Returns the error "422 Unprocessable Entity". Here is my code and most likely it is related to downloading the file. Intentionally removed and simplified the entire code
`@app.post('/test/almost whole')
async def create_catch(catch: tag_shemas.CatchCreate, files: list[UploadFile],
user: User = Depends(current_user),
db: Session = Depends(get_db)):
if not files:
return {"message": "No upload file sent"}
for file in files:
if file.content_type != "image/jpeg":
return {"message": 'incorrect file'}
return crud.create_test(db=db, uploaded_file=files, id=user.id, catch=catch)
CRUD
def create_catch(db: Session, uploaded_file, id, catch: tag_shemas.CatchCreate):
db_geo = models.Geo(coordinates_n=catch.coordinates_n, coordinates_e=catch.coordinates_e)
db_description = models.Descriptions(description=catch.description, user_id=id)
db.add_all([db_geo, db_description])
db.commit()
db.refresh(db_geo)
db.refresh(db_description)
db_tag = models.Tags(description_id=db_description.id, geo_id=db_geo.id, user_id=id)
db.add(db_tag)
db.commit()
db.refresh(db_tag)
for file in uploaded_file:
file_location = rf"C:\Users\v/{file.filename}"
with open(file_location, 'wb+') as file_object:
shutil.copyfileobj(file.file, file_object)
db_photo = models.Photos(tags_id=db_tag.id, description_id=db_description.id, photo_url=file_location)
db.add(db_photo)
db.commit()
return {'OOOOOkkkk'}`
When I remove the part with the file upload, everything works fine. I can't figure out where the error is. Most likely something syntactic