#๐ Request failed with status code 422
35 messages ยท Page 1 of 1 (latest)
@agile thistle
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
How can I resolve this issue? I can provide any code snippet you want... just tell me where is the error occuring..
I am using react and postgreSQL with fastAPI
@app.get("/scan-files/{user_id}", response_model=List[ScanResult])
async def scan_files(user_id: int, db: Session = Depends(SessionLocal)):
user_files = db.query(UserFile).filter(UserFile.user_id == user_id).all()
if not user_files:
raise HTTPException(status_code=404, detail="No files found for the user")
scan_results = []
for db_file in user_files:
with tempfile.TemporaryDirectory() as temp_dir:
temp_file_path = os.path.join(temp_dir, db_file.fname)
with open(temp_file_path, "wb") as temp_file:
temp_file.write(db_file.data)
try:
virus_scan_task = asyncio.create_task(scan_file_with_clamav(temp_file_path))
stego_scan_task = asyncio.create_task(check_steganography(temp_file_path))
virus_scan_result, stego_scan_result = await asyncio.gather(virus_scan_task, stego_scan_task)
# Interpret the scan results
has_virus = virus_scan_result["status"] == "infected"
has_steganography = stego_scan_result["status"] == "infected"
except Exception as e:
logger.error(f"Error scanning file {db_file.fname}: {e}")
has_virus = False
has_steganography = False
scan_results.append({
"file_id": db_file.id,
"file_name": db_file.fname,
"has_virus": has_virus,
"has_steganography": has_steganography,
})
return scan_results
422 = Unprocessable Entity, so there's a problem with the POST data
that means the .js part of the code
the post data fails the validation so that endpoint code doesn't get to run
oh wait
this is a GET endpoint
yes
does it run to the point where you're returning the list?
how is ScanResult defined? Do you get a response body? what about errors in the server logs?
i am unable to check for its functionality because it asks for two parameters
idk what local_kw is but it is a required field...
i wanted that it would just take user_id and scan all the files of that user
why not just use Postman or another HTTP client to check?
where did you go?
Not sure if I understood this so please correct me. You made this API endpoint but you don't know what local_kw is and why its a required field?
i also dont know where did I put the parameter local_kw
what does your post request look like?
this
Also I just noticed that this is a GET route. Do you have one for POST?
const handleScanAll = async () => {
if (!user_id || !token) return; // Check if user_id and token are available
setIsLoading(true); // Show loading indicator
setScanResults([]); // Clear previous results
setErrorMessage(''); // Clear any existing error message
try {
const response = await axios.get(`http://127.0.0.1:8000/scan-files/${user_id}`, {
headers: {
'Authorization': `Bearer ${token}`,
},
});
setScanResults(response.data); // Update state with new scan results
} catch (error) {
console.error('Error scanning files:', error || error.response.data);
setErrorMessage('Failed to scan the files. Please try again.'); // Set error message
} finally {
setIsLoading(false); // Hide loading indicator
}
};
no this will return the scanned result
or will it?
@wet mango
What does your terminal show?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.