Pergunta

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 tested it, it worked without problems but on the users computer the problem exists. I wasn't able to reproduce the problem, so I was wondering if there was a bug in Python 3.3.1 which causes the header problems or if I have a problem in the source code.

You can find the source code here. A screenshot of the problem can be found here.

Because the headers aren't send properly the HTML etc. becomes invalid and isn't displayed as HTML because the browser doesn't get the header for content type.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top