</>CodeWithKarani
All topics
Topic

Python & FastAPI

FastAPI, async, packaging and the ORM - building and shipping Python services without the event loop or the dependency tree fighting you.

Sub-topics

33 articles · showing 1-9 (page 1 of 4)

Payments & Fintech6 min read

M-Pesa Reconciliation That Scales: From Paybill Statement to Trial Balance

Stop reconciling in spreadsheets. A three-way match between the Safaricom statement, your callback events and a double-entry ledger, with named break categories and a daily close job in Python and SQL.

Read
Payments & Fintech7 min read

M-Pesa "Invalid BusinessShortCode": The Python requests Bug Behind It

Daraja error 400.002.02 blames your shortcode, but the real cause is usually data=payload instead of json=payload in Python requests. Here is how to prove it.

Read
Databases8 min read

MySQL server has gone away: four unrelated causes, one message

Errors 2006 and 2013 are a shrug, not a diagnosis. Idle timeouts, packet size, read timeouts and a crashed server all produce them, and each needs a completely different fix.

Read
Databases8 min read

FATAL: sorry, too many clients already - and why raising max_connections is wrong

Every Postgres connection is a separate OS process, so raising max_connections trades a clear error for an OOM. Here is the connection maths and the PgBouncer fix.

Read
Databases10 min read

Your Redis Cache Is Serving Yesterday's Data: Fixing Invalidation Properly

Stale cache incidents have no error message, only a DEL that returns 0. Here is why Redis invalidation breaks, the structural fix, and how to prove it worked.

Read
Python & FastAPI8 min read

Celery's unresolved worker memory leak: what actually helps when nothing fixes it

Celery's parent process RAM climbs for days with no confirmed cause upstream. Here is what the open issue really says, and the mitigations that hold your server up meanwhile.

Read
Python & FastAPI8 min read

The asyncio SSL Memory Leak Nobody Warns You About, and How to Work Around It

Long-running asyncio TLS services can leak memory in the SSL transport, growing RSS until the OOM killer strikes. Here is how to confirm it, mitigate it, and track the real fix.

Read
Payments & Fintech9 min read

Daraja 404.001.03: Cache the Access Token, Don't Mint a New One

M-Pesa Daraja tokens live about an hour. Fetching one per request gets you throttled; caching forever gets you 404.001.03. The proactive refresh pattern Safaricom never documents.

Read
Python & FastAPI8 min read

FastAPI 422 Unprocessable Entity: Read the Error Body Instead of Guessing

FastAPI already tells you exactly which field is wrong in the 422 response body. Stop relaxing validation. Read detail[].loc, and fix the three payload mistakes that cause almost every 422.

Read
Python & FastAPI - Guides, Sub-topics & Fixes · Code With Karani