Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #671 (defect)

Opened 2 years ago

Last modified 2 years ago

KeyError: 'Host' - CherryPy 3.01 - tut01_helloworld.py

Status: closed (fixed)

Reported by: guest Assigned to: rdelon
Priority: normal Milestone: 3.1
Component: CherryPy code Keywords: tutorial bug KeyError
Cc:

I cannot visit http://localhost:8080/ and get a webpage...

The connection was refused when attempting to contact localhost:8080.

Now, telnet localhost 8080 works just fine... but the resulting page is broken with the 3.01 stable release I just downloaded:

<!-- ~/tmp tbrannon --> telnet localhost 8080
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 500 Internal Server Error
Date: Fri, 09 Mar 2007 15:45:27 GMT
Content-Length: 1109
Content-Type: text/html
Server: CherryPy/3.0.1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;
charset=utf-8"></meta>
    <title>500 Internal Server Error</title>
    <style type="text/css">
    #powered_by {
        margin-top: 20px;
        border-top: 2px solid black;
        font-style: italic;
    }

    #traceback {
        color: red;
    }
    </style>
</head>
    <body>
        <h2>500 Internal Server Error</h2>
        <p>The server encountered an unexpected condition which
prevented it from fulfilling the request.</p>
        <pre id="traceback">Traceback (most recent call last):
  File "/sw/lib/python2.5/site-packages/cherrypy/_cprequest.py", line
524, in respond
    self.process_headers()
  File "/sw/lib/python2.5/site-packages/cherrypy/_cprequest.py", line
599, in process_headers
    host = dict.__getitem__(headers, 'Host')
KeyError: 'Host'
</pre>
    <div id="powered_by">
    <span>Powered by <a href="http://www.cherrypy.org">CherryPy 3.0.1</
a></span>
    </div>
    </body>
</html>
Connection closed by foreign host.
<!-- ~/tmp tbrannon -->

Change History

03/09/07 12:19:21: Modified by fumanchu

  • description changed.

03/09/07 12:26:47: Modified by fumanchu

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [1636] (trunk and 3.0 branch). HTTP/1.1 requires a Host header, but HTTP/1.0 (which you're sending) does not. The code in _cprequest erroneously used dict.__getitem__ instead of dict.get.

Hosted by WebFaction

Log in as guest/cpguest to create tickets