The errata list is a list of errors and their corrections that were found after the product was released.
The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.
Version |
Location |
Description |
Submitted by |
Date submitted |
Printed |
Page 7
Example 1-2, lines 19,20 |
code snipset:
width = self.get_argument('width', 40)
self.write(textwrap.fill(text, width))
If there is no "width" argument in the POST request, then default value 40 will be used, and "get_argument" returns integer.
Variable "width" is INTEGER 40.
Example 1-2 works correctly.
If there is "width" argument in the POST request (let's say width=10),
then "get_argument" returns unicode string.
Variable "width" is now unicode string u'10'.
Example 1-2 now crashes in function textwrap.fill
In any case, thank you for the very interesting book.
Peter Leonov
|
Anonymous |
Apr 19, 2012 |
PDF |
Page 17
code |
This is not an errata, but a remainder for the reader using Tornado 2.2 on Python 3.2.2:
Don?t forget that in Python 3.2 the print method requires parenthesis surrounding the argument to be printed. The book?s code is written in Python 2.X series, so the reader must adjust the code lines involving the print statement.
For example, on page 17 we find the following statement:
print content.generate(header="Welcome!") # OK in Python 2.X series
So, if we?re working with Tornado 2.2 on Python 3.2.2, we must add surrounding parenthesis to avoid a mundane syntax error:
print( content.generate(header="Welcome!") ) # OK in Python 3.2 series
|
ederandresan |
Apr 10, 2012 |
PDF |
Page 38
Example 3-1 code |
On Ex 3-1, ui_modules needs to be a dictionary, so the line
> ui_modules={'Hello', HelloModule}
should be
> ui_modules={'Hello' : HelloModule}
|
george |
Mar 30, 2012 |
|
38
middle of page, __main__ |
ui_modules={'Hello', HelloModule} should read:
ui_modules={'Hello': HelloModule}
(is a Python dictionary, needs a colon and not a comma as separator)
|
Caleb Wright |
Apr 03, 2012 |
PDF |
Page 38
code |
p038: Tornado 2.2 on Python 3.2.2. Missing import statement to execute the example app.
import tornado.web
import tornado.httpserver
import tornado.ioloop
import tornado.options
import os.path
It should be: ====>>>
import tornado.web
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.locate
import os.path
|
ederandresan |
Apr 10, 2012 |
PDF |
Page 38
code |
Tornado 2.2 on Python 3.2.2. Dictionary syntax error.
app = tornado.web.Application(
handlers=[(r'/', HelloHandler)],
template_path=os.path.join(os.path.dirname(__file__), 'templates'),
ui_modules={'Hello', HelloModule}
)
===================================>>>
app = tornado.web.Application(
handlers=[(r'/', HelloHandler)],
template_path=os.path.join(os.path.dirname(__file__), 'templates'),
ui_modules={'Hello': HelloModule}
|
ederandresan |
Apr 10, 2012 |
PDF |
Page 57
Example 4-3 |
Unused import statment:
import tornado.auth
import tornado.escape
|
Matheus |
Jul 29, 2012 |
PDF |
Page 69
Example 5-1 , line 7 and line 20 |
In python3.2 change the values:
import urllib
urllib.urlencode({"q": query, "result_type": "recent", "rpp": 100}))
To:
import urllib.parse
urllib.parse.urlencode({"q": query, "result_type": "recent", "rpp": 100}))
|
Matheus |
Aug 02, 2012 |
PDF |
Page 69
Example 5-3, line 21 |
In python3.2 json problem, need to decode it.
Change the values:
body = json.loads(response.body)
To:
body = json.loads(response.body.decode('utf-8'))
|
Matheus |
Aug 02, 2012 |
|
69
code segment |
The example uses twitter api v1 which is no longer supported, and as a result, you get an error 410
{"errors": [{"message": "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68}]}
|
eran |
Oct 10, 2013 |
PDF |
Page 94
cookie_counter.py get method |
The following part is syntactically incorrect.
self.write(
'<html><head><title>Cookie Counter</title></head>'
'<body><h1>You’ve viewed this page %s times.</h1>' % countString
'</body></html>'
)
You need to join string literals with '+'
self.write(
'<html><head><title>Cookie Counter</title></head>' +
'<body><h1>You’ve viewed this page %s times.</h1>' % countString +
'</body></html>'
)
|
george |
Apr 03, 2012 |
PDF |
Page 99
Example 6-3. Login form: login.html |
"xsrf_cookies" is set to true in the application, but xsrf_form_html declaration is missing from the login form.
|
george |
Apr 03, 2012 |
PDF |
Page 100
code |
Tornado 2.2 on Python 3.2.2. Missing RequestHandler.xsrf_form_html() method in the login.html file in order to Tornado process the post login request using the xsfr cookie protection:
Example 6-3. Login form: login.html
<html>
<head>
<title>Please Log In</title>
</head>
<body>
<form action="/login" method="post">
Username:<input type="text" name="username"/>
<input type="submit" value="Log In" />
</form>
</body>
</html>
===================================>>>
Example 6-3. Login form: login.html
<html>
<head>
<title>Please Log In</title>
</head>
<body>
<form action="/login" method="post">
{% raw xsrf_form_html() %}
Username:<input type="text" name="username"/>
<input type="submit" value="Log In" />
</form>
</body>
</html>
|
ederandresan |
Apr 10, 2012 |
PDF |
Page 116-117
Source code |
# Need to put upstream into http block:
worker_processes 2;
events
{
worker_connections 1024;
use epoll;
}
http
{
upstream tornadoes
{
server 127.0.0.1:8000;
server 127.0.0.1:8001;
}
server
{
listen 80;
server_name localhost;
location /reverse/
{
root /home/s/web/static;
if ($query_string)
{
expires max;
}
}
location /
{
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://tornadoes;
}
proxy_next_upstream error;
}
}
|
Anonymous |
Jun 15, 2012 |