Overview
This guide covers common issues you might encounter when developing or deploying the ExpireEye Backend API, along with their solutions.Database Connection Errors
Connection Refused
Error: Can't connect to MySQL server on 'localhost'
Error: Can't connect to MySQL server on 'localhost'
- MySQL server is not running
- Wrong host/port in configuration
- Firewall blocking connection
-
Verify MySQL is running:
-
Check connection details in
.env: -
Test connection manually:
-
Check if port 3306 is open:
app/db/session.py:11-17. Make sure all environment variables are set correctly.Authentication Failed
Error: Access denied for user
Error: Access denied for user
- Incorrect username or password
- User doesn’t have access to the database
- Password contains special characters not properly escaped
-
Verify credentials:
-
Grant proper permissions:
-
If password has special characters:
-
Reset user password:
Database Does Not Exist
Error: Unknown database
Error: Unknown database
Connection Pool Timeout
Error: Connection pool timeout / Too many connections
Error: Connection pool timeout / Too many connections
- Not closing database sessions properly
- Too many concurrent requests
- Database connection leaks
-
The connection pool is configured in
app/db/session.py:24-31: -
Increase pool size if needed:
-
Ensure sessions are properly closed:
The
get_db()dependency handles this automatically (app/db/session.py:37-42). -
Monitor active connections:
Authentication Errors
Missing Authorization Header
Error: Authorization header missing or invalid
Error: Authorization header missing or invalid
Invalid or Expired Token
Error: Access token is invalid
Error: Access token is invalid
- Token has expired (4000 minutes after creation)
- Token is malformed or corrupted
- Secret key changed since token was issued
- Token was decoded with wrong algorithm
-
Get a new token by logging in again:
-
Check token expiration:
Tokens expire after 4000 minutes (configured in
app/utils/jwt.py:9). Decode your token at jwt.io to check theexpclaim. -
Verify SECRET_KEY hasn’t changed:
If you changed the SECRET_KEY, all existing tokens are invalidated.
-
Ensure token is properly formatted:
- Should start with “Bearer ”
- Three parts separated by dots:
xxx.yyy.zzz - No extra whitespace or line breaks
Invalid Login Credentials
Error: Invalid email or password
Error: Invalid email or password
-
Verify email exists:
Check the database directly:
-
Reset password if forgotten:
Update password in database (hash it first):
Then update in database:
-
Check for typos:
- Email addresses are case-sensitive
- Remove leading/trailing spaces
app/routers/auth.py:31-32. The password is compared against the hashed version stored in the database.CORS Errors
Cross-Origin Request Blocked
Error: CORS policy blocked the request
Error: CORS policy blocked the request
- Frontend origin not in allowed list
- Preflight request failing
- Missing CORS middleware configuration
-
Add your frontend origin to the allowed list:
Edit
app/main.py:34-39: -
For development, temporarily allow all origins:
-
Verify CORS middleware is configured:
Check
app/main.py:42-48- should include CORSMiddleware. -
Ensure credentials are allowed:
-
Check preflight requests:
The middleware handles OPTIONS requests (
app/main.py:55-56).
Credentials Not Sent
Cookies not being sent cross-origin
Cookies not being sent cross-origin
File Upload Errors
File Too Large
Error: Request entity too large
Error: Request entity too large
- File exceeds FastAPI’s default limit
- Reverse proxy (nginx) limiting request size
-
For uvicorn, no default limit, but add one if needed:
-
If using nginx, update config:
-
Validate file size before upload:
Invalid File Type
Error: Cannot process file / Image decode error
Error: Cannot process file / Image decode error
- Uploaded file is not a valid image
- Image format not supported by OpenCV
- File is corrupted
-
Validate file type before processing:
-
Check file content type:
-
Supported formats for YOLO/QR detection:
- JPEG (.jpg, .jpeg)
- PNG (.png)
- BMP (.bmp)
uploads/ directory (app/main.py:136-143). Ensure this directory exists and has write permissions.Upload Directory Missing
Error: No such file or directory: 'uploads/'
Error: No such file or directory: 'uploads/'
Validation Errors
Missing Required Fields
Error: Field required
Error: Field required
- Request body missing required fields
- Field name misspelled
- Sending wrong data type
-
Check the API schema in
/docs: Each endpoint shows required fields marked with an asterisk (*) -
Ensure all required fields are included:
-
Check field names match exactly:
Field names are case-sensitive:
emailnotEmail
app/main.py:99-115. It formats Pydantic validation errors into a more user-friendly format.Invalid Data Format
Error: Invalid date format / Value is not a valid email
Error: Invalid date format / Value is not a valid email
-
Use correct date format (ISO 8601):
-
Ensure email is valid:
-
Check data types:
- Numbers should not be strings:
"quantity": 5not"quantity": "5" - Booleans:
trueorfalse(lowercase, no quotes) - Arrays:
[1, 2, 3]not"1,2,3"
- Numbers should not be strings:
Scheduler Issues
Scheduler Not Running
Scheduled jobs not executing
Scheduled jobs not executing
- Application not fully started
- Scheduler exception during initialization
- Event loop issues
-
Check startup logs:
Look for:
-
Verify scheduler configuration:
Check
app/main.py:171-175: -
Check for errors in scheduled function:
Add error handling to
check_product_expiryfunction. -
Ensure APScheduler is installed:
-
Monitor scheduler execution:
Add logging to see when jobs run:
Jobs Running Too Frequently
Scheduled jobs executing multiple times
Scheduled jobs executing multiple times
- Multiple server instances running
- Scheduler not properly shut down
--reloadcreating duplicate processes
-
Check for multiple processes:
Kill duplicates:
-
Ensure proper shutdown:
The shutdown event handler stops the scheduler (
app/main.py:178-180): -
For production, use a single worker:
Or use a distributed job queue (Celery, RQ) for multi-worker setups.
Environment and Configuration
Environment Variables Not Loaded
Error: SECRET_KEY is None
Error: SECRET_KEY is None
.envfile not in project root- Environment variables not loaded
- Typo in variable names
-
Verify
.envfile location:Should be in the same directory asapp/folder. -
Check
.envfile contents:Required variables:DB_USERDB_PASSWORDDB_HOSTDB_PORTDB_NAMESECRET_KEY
-
Ensure python-dotenv is installed:
-
Check for typos in variable names:
Variable names in
.envmust match exactly what’s used in code:app/db/session.py:11-15app/utils/jwt.py:8
-
Load environment variables manually for testing:
Getting Help
If you’re still experiencing issues:-
Check the logs:
-
Enable SQLAlchemy query logging:
-
Test with minimal example:
Create a simple test endpoint to isolate the issue:
- Review error stack traces: FastAPI provides detailed error messages in development mode.