--- name: ahserver-post-debugging description: "Fix ahserver POST 405, upload hang, or empty params_kw." version: "1.0.0" tags: ["ahserver", "aiohttp", "post", "debugging"] --- # ahserver POST Debugging ## 1. POST 405 — `_allowed_methods` not updated `ProcessorResource.__init__` updates `_routes` but not `_allowed_methods`. aiohttp checks the latter. **Fix:** After `self._routes.update(...)`, add: ```python self._allowed_methods = set(self._routes.keys()) ``` ## 2. Upload hangs — `client_max_size` too small Default `client_max_size: 10000` (bytes). Files >10KB hang silently. **Fix:** Set in `conf/config.json`: ```json "website": { "client_max_size": 104857600 } ``` ## 3. `params_kw` empty for multipart — auth crashes `getPostData()` → `get_session_user()` → `auth.get_auth()` raises `RuntimeError` without middleware. Exception breaks the multipart loop, `params_kw` stays empty. **Fix:** In `auth_api.py`: ```python async def get_session_userinfo(request): try: d = await auth.get_auth(request) except: d = None ... ``` ## 4. Handler `request.read()` empty — body consumed `getPostData()` already reads the body before handler runs. Use `params_kw` + `FileStorage.realPath()` instead. ## Diagnostic order 1. 405? → fix `_allowed_methods` 2. Small works, large hangs? → fix `client_max_size` 3. `params_kw` empty? → fix auth 4. Body empty? → use `params_kw`