-1

Everytime i run my code in Chrome. It returns two request. Second is favicon.ico

But Favicon.ico's content type is text/html and status is 500

How can i change its status to 404

i dont have favicon.ico and i dont want to

IMAGE

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Arda Nalbant
  • 479
  • 2
  • 7
  • 16

2 Answers2

3

You are getting 500, probably because /favicon.ico matches different route (e.g. with template without required params).

@Daniel B. answer is ok, (some) browsers won't request favicon - complete info can be found at How to prevent favicon.ico requests?. Additionally I would add ErrorHandler route to server 404.

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

def make_app():
    return tornado.web.Application([
        (r"/favicon.ico", tornado.web.ErrorHandler, {'status_code': 404}),
        (r".*", MainHandler),
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

There are also apple-*ico requested by Apple devices, you may want to send 404 as well.

Community
  • 1
  • 1
kwarunek
  • 12,141
  • 4
  • 43
  • 48
  • Thanks for reply. This helps me a lot.Because if i dont have a html file and the answer below couldn't help me.Thanks again i wish i could upvote but i cant – Arda Nalbant Mar 11 '16 at 13:06
2

Not sure why you get a 500, but if you don't want a favicon at all maybe you could add an empty one to your htmls head?

<link rel="shortcut icon"type="image/x-icon" href="data:image/x-icon;,">
Daniel B.
  • 929
  • 4
  • 8