Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Flask Basics Welcome to Flask First Steps

Iskander Ismagilov
Iskander Ismagilov
13,298 Points

'utf-8' codec can't decode byte 0xcf [SOLVED]

Hi, everybody! I have a problem, when I try to launch this code locally, using PowerShell on Windows 7:

from flask import Flask

app = Flask(__name__)

app.route('/')
app.route('/<name>')
def index(name="Treehouse"):
    return "Hello from {}".format(name)

app.run(debug=True, port=8000, host='127.0.0.1') # I changed host, so I can get to the page using my browser.

and when I run this script, it throws an exception:

  File "c:\python35\Lib\socket.py", line 658, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 2: invalid continuation byte

Is it because of some problem with utf to convert some symbols in uncode?

2 Answers

Iskander Ismagilov
Iskander Ismagilov
13,298 Points

Thank's Chris,

I got it, I found this document: http://bugs.python.org/issue9377. So the prooblem was because of non-ASCII symbols in the host name of my computer, so after I figure out that the name of my computer and the host name of my computer are the same, I just changed it.

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Not sure about the byte decode issue, but there is another issue with your code.

The app.route decorators need to be prefixed with an at sign @

@app.route('/')
@app.route('/<name>')
def index(name="Treehouse"):
    return "Hello from {}".format(name)

Post back if that's not the issue.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Fantastic! I would not have figured it out with my current environment