Reputation: 3113
Attempting Docker get-started example I continue to get the indentation error message included at the bottom of this question and I cannot diagnose the problem. I have edited the copy/paste version from the link to "look like" the browser view and have replaced all Tabs with 4 spaces. But I do not understand the code itself well enough to know if the browser indented view looks like its meant to or not.
My version of the app.py
code is as follows.
from flask import Flask
from redis import Redis, RedisError
import os
import socket
# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
app = Flask(__name__)
@app.route("/")
def hello():
try:
visits = redis.incr("counter")
except RedisError:
visits = "<i>cannot connect to Redis, counter disabled</i>"
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>" \
"<b>Visits:</b> {visits}"
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)
The error is enclosed in the console session below.
server:docker0 brian$ docker run -p 4000:80 friendlyhello
File "app.py", line 15
except RedisError:
^
IndentationError: unexpected indent
server:docker0 brian$
How can I fix the error?
Upvotes: 0
Views: 817
Reputation: 3113
While continuing to debug, as a test I deleted the word RedisError
from the except
line. But the error message still contained RedisError
. That was my clue that the app.py I thought was being executed was not being executed. I had to execute docker build ./ -t friendlyhello
again before I could docker run
.
Upvotes: 1