RuntimeError: headers have already been sent

27 views
Skip to first unread message

Velu Narasimman

unread,
Mar 4, 2020, 12:41:57 AM3/4/20
to Trac Users
Hi team,

    I am facing this "headers have already been sent" error in an AJAX call. I am not able to fix it. I need your hellp. Would be better if someone could explain this issue.

2020-03-04 11:00:45,582 Trac[main] ERROR: [172.24.188.116] Internal Server Error: <RequestWithSession "POST '/admin/pros users/users'">, referrer 'https://prism30.aspiresys.com/Merlin/admin/pros%20users/users'
Traceback (most recent call last):
 
File "/usr/local/lib/python2.7/dist-packages/Trac-1.0.15-py2.7.egg/trac/web/main.py", line 631, in _dispatch_request
    dispatcher
.dispatch(req)
 
File "/usr/local/lib/python2.7/dist-packages/Trac-1.0.15-py2.7.egg/trac/web/main.py", line 325, in dispatch
    req
.send(output, content_type or 'text/html')
 
File "/usr/local/lib/python2.7/dist-packages/Trac-1.0.15-py2.7.egg/trac/web/api.py", line 556, in send
   
self.end_headers()
 
File "/usr/local/lib/python2.7/dist-packages/Trac-1.0.15-py2.7.egg/trac/web/api.py", line 476, in end_headers
   
self._write = self._start_response(self._status, self._outheaders)
RuntimeError: headers have already been sent

Above chunk is the error. And below is how I write my json response to the AJAX call.
    def respond(self, req, data, code=200):
       
"""Respond to the JSON request by sending the JSON-encoded data back."""
        json_data
= json.dumps(data)
        req
.send_response(code)
        req
.send_header('Content-Type', 'application/json')
        req
.send_header('Content-Length', len(json_data))
        req
.write(json_data)
       
raise RequestDone

Not sure if I am missing any code here in this respond method. Welcome your suggestions to fix this error.

Jun Omae

unread,
Mar 4, 2020, 3:28:46 AM3/4/20
to trac-...@googlegroups.com
That is due to Request.end_headers() called twice. Please report it to
the plugin maintainers.
--
Jun Omae <jun...@gmail.com> (大前 潤)

Velu Narasimman

unread,
Mar 4, 2020, 8:45:41 AM3/4/20
to Trac Users
This error is happening in the core Trac package. Whom should I report to? Also I am using similar code in few other area. There it works well.

Jun Omae

unread,
Mar 4, 2020, 8:47:27 AM3/4/20
to trac-...@googlegroups.com
Please share entire of the plugin code. I believe the plugin has the problem(s).
> --
> You received this message because you are subscribed to the Google Groups "Trac Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/a6858f6d-fe2e-491b-ab23-f399fc2ebe2d%40googlegroups.com.

Velu Narasimman

unread,
Mar 4, 2020, 8:52:32 AM3/4/20
to Trac Users
Sorry, do you mean the Trac code? I am using trac 1.0.15 version and you can find the same here. Now it is archived.
> To unsubscribe from this group and stop receiving emails from it, send an email to trac-...@googlegroups.com.

Jun Omae

unread,
Mar 4, 2020, 10:03:54 AM3/4/20
to trac-...@googlegroups.com
No. Please share your installed plugin, not Trac. The installed plugin has something wrong and the wrong leads the error.


To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/9f21c412-8ff3-4384-b3ae-4339c8be6f14%40googlegroups.com.

Jun Omae

unread,
Mar 4, 2020, 10:06:42 AM3/4/20
to trac-...@googlegroups.com
In addition, post System Information, Installed Plugins and configuration from about page of your Trac.

On Thu, Mar 5, 2020 at 0:03 Jun Omae <jun...@gmail.com> wrote:
No. Please share your installed plugin, not Trac. The installed plugin has something wrong and the wrong leads the error.
--
Reply all
Reply to author
Forward
0 new messages