Python 3 Http Server Sends Headers As Output
In my GitHub project there is currently an Issue which is caused by Python 3.3.1. The builtin HTTP server of Python I'm using seems to send the headers as a normal output. When I t
Solution 1:
I just found the problem. It seems that Python versions after >= 3.3.x require to send the status code before the first header. Otherwise the header is handled as a normal output. So I switched it and now it works. Below just an example:
Does not work:
self.send_header('Content-type', 'text/html')
self.send_response(200)
Works:
self.send_response(200)
self.send_header('Content-type', 'text/html')
By the way: The Internet Explorer doesn't have this problem. But of course the HTTP specifications require to send the status just before the headers. But earlier Python versions were able to deal with it. This is why I weren't able to reproduce the problem when I tried it the first times.
Post a Comment for "Python 3 Http Server Sends Headers As Output"