#13492 closed defect (fixed)
Uploading an attachment fails with "AssertionError: write() before start_response()" (mod_fcgid)
| Reported by: | arroz | Owned by: | Jun Omae |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.5.4 |
| Component: | web frontend | Version: | 1.5.3 |
| Severity: | critical | Keywords: | fcgi, attachment |
| Cc: | miguel.arroz@… | Branch: | trunk |
| Release Notes: |
Fix internal server error when uploading files using fcgi. |
||
| API Changes: | |||
| Internal Changes: | |||
Description
Running Trac 1.5.4.dev0 (0182158c5cb676af5b40cf1714c3d29c28a9d632 from the git repository). Not sure if the problem actually happens in 1.5.3, I need to be on trunk due to a different issue, so consider this 1.5dev (that version isn't available in the list).
When uploading an attachment to a ticket, I get the following error on the browser. This doesn't seem to depend on either the name or size of the attachment (a one byte file with a name with no special chars or spaces triggers the problem).
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/trac/web/_fcgi.py", line 572, in run
protocolStatus, appStatus = self.server.handler(self)
File "/usr/local/lib/python3.9/site-packages/trac/web/_fcgi.py", line 1250, in handler
write(b'') # in case body was empty
File "/usr/local/lib/python3.9/site-packages/trac/web/_fcgi.py", line 1203, in write
assert headers_set, 'write() before start_response()'
AssertionError: write() before start_response()
Attachments (0)
Change History (5)
comment:1 by , 3 years ago
| Cc: | added |
|---|
comment:2 by , 3 years ago
| Component: | attachment → web frontend |
|---|---|
| Keywords: | fcgi added |
| Milestone: | → 1.5.4 |
| Owner: | set to |
| Status: | new → assigned |
comment:3 by , 3 years ago
Thanks for the super quick feedback.
Yeah, that patch works perfectly! I can now upload attachments without issues. Thank you! 🙏 Sorry for not including the more detailed trace originally.
comment:4 by , 3 years ago
| Release Notes: | modified (diff) |
|---|---|
| Resolution: | → fixed |
| Status: | assigned → closed |
Committed in [17604]. Thanks for the reporting, again!



Thanks for the report! I get the following traceback on reproducing the issue:
10:54:36 Trac[main] ERROR: [192.168.11.15] Internal Server Error: <RequestWithSession "POST '/attachment/ticket/102'">, referrer 'http://192.168.11.122:3000/1.5-sqlite/attachment/ticket/102/?action=new' Traceback (most recent call last): File "/vol/src/tracdev/git/trac/web/main.py", line 610, in dispatch_request dispatcher.dispatch(req) File "/vol/src/tracdev/git/trac/web/main.py", line 302, in dispatch raise e File "/vol/src/tracdev/git/trac/web/main.py", line 207, in dispatch if handler.match_request(req): File "/vol/src/tracdev/git/trac/attachment.py", line 168, in match_request req.args['realm'] = realm File "/vol/src/tracdev/git/trac/web/api.py", line 569, in __getattr__ value = self.callbacks[name](self) File "/vol/src/tracdev/git/trac/web/api.py", line 551, in <lambda> 'args': lambda req: arg_list_to_args(req.arg_list), File "/vol/src/tracdev/git/trac/web/api.py", line 569, in __getattr__ value = self.callbacks[name](self) File "/vol/src/tracdev/git/trac/web/api.py", line 943, in _parse_arg_list fs = _FieldStorage(fp, environ=self.environ, File "/usr/lib/python3.9/cgi.py", line 480, in __init__ self.read_multi(environ, keep_blank_values, strict_parsing) File "/vol/src/tracdev/git/trac/web/api.py", line 272, in read_multi cgi.FieldStorage.read_multi(self, *args, **kwargs) File "/usr/lib/python3.9/cgi.py", line 617, in read_multi first_line = self.fp.readline() # bytes File "/vol/src/tracdev/git/trac/web/_fcgi.py", line 185, in readline i = self._buf.find('\n', self._pos) TypeError: argument should be integer or bytes-like object, not 'str'I've fixed fcgi issue #13403 but the fix was incomplete.
Could you please try the following patch?
trac/web/_fcgi.py
'\n', self._pos)